Word 2003 Header and Footer Field Refresh for Multiple Section Documents

March 16, 2006 at 9:07 pm 10 comments

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 HeaderFooter

 For 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

Entry filed under: Macro, Word 2003.

Travel Journal: Newark, Notthinghamshire Threat Level Red for Local Salons

10 Comments Add your own

  • 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!

    Reply
  • 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.

    Reply
  • 3. Timo  |  July 28, 2008 at 7:26 am

    Thanks a lot… this piece of code saves me a lot of time 🙂

    Reply
  • 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?

    Reply
  • 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 […]

    Reply
  • 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.

    Reply
  • 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.

    Reply
  • 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! 😦

    Reply
  • 9. Miranda  |  August 6, 2010 at 8:05 am

    Thank you so much! This did exaclty what I needed in a very complex document! It’s also the first time I’ve ever successfully placed and used a macro, so I feel quite certain that anybody could do this. I’ve tried creating them before, but I have no skill and no background in scripting/programming or whatever this qualifies as. So, thanks again! This is really going to make me look good at work! Genius!

    Reply
  • 10. Mezők automatikus frissítése Word 2007-ben « MS Workshop  |  October 13, 2010 at 4:36 pm

    […] a mezőket, a többiben nem. Némi keresgélés után akadtam rá erre a blog bejegyzésre: Word 2003 Header and Footer Field Refresh for Multiple Section Documents   Az előző makró már alkalmas arra, hogy a fájl megnyitásakor frissítsen minden mezőt […]

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Flickr Photos

3D Printed Products

Tweets


%d bloggers like this: