Word 2003 Header and Footer Field Refresh for Multiple Section Documents
March 16, 2006
In Word, you can insert a lot of properties information into the Headers and Footers. Most commonly Page Numbers is used. There are built in properties such as FILENAME. In addition under File->Properties; Custom– you can add your own properties. All of these can be inserted directly into the headers and footers. In Word 97 and Word 2000 when you first opened the document, Word would automatically refresh that information for you.
In Word 2002 and Word 2003, that information is not automatically refreshed. It will display old information until you:
1) Switch View mods under the View menu
2) Print the document
3) Right click on a field and select “Update Field“
Microsoft documents this behavior in KB832897: The FILENAME field does not automatically update when you open a document in Word 2002 or Word 2003 (http://support.microsoft.com/kb/832897/en-us)
In there they provide code for a macro that will run each time the document is opened and refresh all the fields in the headers and footers. The macro works well— but if you have multiple sections in your document, only the first section is refreshed.
Below is a modified macro that will handle documents with multiple sections. Follow all the instructions in the Microsoft article, but use the following code instead:
Sub AutoOpen()
Dim aStory As Range
Dim aField As Field
Dim aSection As Section
Dim aHeaderFooter As HeaderFooterFor Each aSection In ActiveDocument.Sections
For Each aHeaderFooter In aSection.Headers
Set aStory = aHeaderFooter.Range
For Each aField In aStory.Fields
aField.Update
Next aField
Next aHeaderFooter
For Each aHeaderFooter In aSection.Footers
Set aStory = aHeaderFooter.Range
For Each aField In aStory.Fields
aField.Update
Next aField
Next aHeaderFooter
Next aSection
End Sub
8 Comments Add your own
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed






1.
Clint | March 21, 2006 at 3:05 pm
And the time it cost to pay an employee to figure this out? Less than the cost of a different word processor.
Word is the bloatiest piece-of-crap I’ve ever used. It makes me long for the days of WordPerfect DOS, with the template that you fit over your F-keys (which wouldn’t fit on an ergonomic keyboard like I use!).
In my past few jobs, I could easily chronicle how bugs in Microsoft Word have caused cost overruns going way over $10,000.
It’s just not worth it.
OpenOffice.org provides a free working interoperable version. I sincerely doubt it shares the same bugs, but I am positive it has far less features than Microsoft’s Word does.
And that may be A Good Thing(tm).
Word — is just so unnecessary.
Especially when you get a 19K email attachment that is simply 8 lines of text in a word doc. It should be less than 1K. . . People who think Word is Notepad should be shot!
2.
A.Nemati | October 29, 2007 at 7:12 am
Very Very Very nice and thanks you.
I had problem with Headers and Footer. Your code was very useful for me. Very thanks agian.
3.
Timo | July 28, 2008 at 7:26 am
Thanks a lot… this piece of code saves me a lot of time
4.
bnpositive | November 24, 2008 at 2:52 pm
I’ve tried your bit of code (Thank you!) but it doesn’t seem to be refreshing the INCLUDEPICTURE field that I have placed in the header. Do you have any ideas why it wouldn’t be including that field?
5. Auto-Refresh INCLUDEPICTURE Field in Word 2007 Mail Merge | November 24, 2008 at 4:00 pm
[...] friend pointed me to this blog entry for Word 2003 Header and Footer Field Refresh for Multiple Section Documents. I thought was going to give me what I was looking for but it doesn’t seem to be working for [...]
6.
tgaw | November 25, 2008 at 9:30 am
@bnpositive – Ooh, sorry– I don’t have a suspicion. It does look like it is getting picked up in the Fields collection and there isn’t a blatant error with the .Update call. So beyond that, I don’t know. If you find out why– let me know! I’m intrigued now.
7.
JT | January 13, 2009 at 11:22 am
Super solution. Short and sessie VBA Code. Did make something myself in the past, very complicated and somehow it did not work anymore.
8.
Jasper Beerens | October 30, 2009 at 6:05 am
Thanks for the info! Just a ‘little’ other question: How can we make this VBA-script work in Word2003-files? The editor keeps telling me he shutsdown the macro’s!