Link to home
Start Free TrialLog in
Avatar of ged125
ged125Flag for United States of America

asked on

Word 2007 Macro to Update Document Properties

Can anyone out there provide some sample code that I could use to prompt and collect values for custom document properties and then do an update of all the fields throughout the doc?  I have a document that has several variables that I currently go in and manually enter, then I do a "CTRL-A" to select all the text and right click and select "Update Fields".  

Is there a way that I could run a macro, be prompted for all the values and then the document would generate itself?  

Thanks in advance.
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Depending on what you require it could be a lot of work.  For example I have devised a form on which I can enter changed data for document properties I add to the document.  On pressing a button all fields are updated, issues creep up with non existing fields so I have various ini sections to address this.

The essence of the update is:
application.customdocumentproperties("propname").value = myform.mytextbox
application.customdocumentproperties("anotherpropname").value = myform.mynexttextbox
...

followed by
 a loop
for each story in activedocument.storyranges
   story.select
   story.fields.update
   selection.collapse direction:=wdcollapsestart
next

myform.hide
application.saved = false

Any help?

Chris
Avatar of ged125

ASKER

would it be possible to get the complete code?
Avatar of ged125

ASKER

application.customdocumentproperties isn't available for me.  Any idea why?
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ged125

ASKER

That's what I was looking for!  Thanks Chris!