Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I update a field code in a Word Header via VBA

Status
Not open for further replies.

dachaney

IS-IT--Management
Sep 3, 2001
84
NL
Hi,

I'm using CustomDocumentProperties in Word 2000 to store some details about a document (in this case a Job number) The propery is set by code in a UserForm and is also shown in the document header by using a Field.

My problem is that when I close the form I want to update the fields in the document to reflect the new values

Using 'ActiveDocument.Fields.Update' updates fields in the body of the document but not in the header

Field code = {DocProperty "SPJOB" \* mergeformat }

userform code snippet
....
ActiveDocument.CustomDocumentProperties("SPJOB").Value = Jobnumber
ActiveDocument.Fields.Update
....


Any ideas ??
I'm using Word 2000 sp3


Thanks In Advance


 
The problem with the code above is that fields in the header/footer do not belong directly to the document. Due to this they are not updated.
Header/footer is section's object, so the reference should be:

[tt]Activedocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Fields.Update[/tt]

if the header belongs to section 1 and header/footer is primary (in opposite to first page or even pages).
 
Thanks for your help

I also came across this bit of code to update all fields in the entire document

Dim aStory As Range
Dim aField As Field
For Each aStory In ActiveDocument.StoryRanges
For Each aField In aStory.Fields
aField.Update
Next aField
Next aStory


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top