Modified document properties when a file is closed

P

Philippe Halet

Hi all,

I would like to add the ability to modified some document properties when a
file is closed. I'm trying to do that with the code below without success.
Any idea?

UserForm1.txtTitle.Text =
ActiveDocument.BuiltInDocumentProperties("Title")
UserForm1.Show vbModal
ActiveDocument.BuiltInDocumentProperties("Title") =
UserForm1.txtTitle.Text

With this code, the document properties is not modified... Very strange!

UserForm1 contains a text field to edit the title of the document and an OK
button.

TIA

Philippe Halet
 
J

Jezebel

What does your form's OK button do? If it unloads the form, then what's
actually happening is your assignment statement creates a NEW instance of
your form (so you lose the value entered on the form). A better construction
would be:

Dim pForm as UserForm1
set pForm = new UserForm1

with pForm
.txtTitle = ActiveDocument.BuiltInDocumentProperties("Title")
.Show vbModal
ActiveDocument.BuiltInDocumentProperties("Title") = .txtTitle
end with
unload pForm
set pForm = nothing


In the form's OK event you want to hide the form, not unload it:

Me.Hide


You might also want to allow for the user to cancel the form.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top