update ALL fields in word 2010 template

AARBRDA1 used Ask the Experts™
Hi all

i have googled around and checked expert exchanges answers and probably tried out 50 different suggestions concerning a macro that updates all fields in a word document when the document is closed or opened. i also tried it with assigning a macro to a toolbar button, but no macro seems to be able to update all fields, e.g. the fields in the footer are never updates unless i F9 into it.

the only way to get it updated automatically is by going to print preview. I must be extremely stupid to not get this to work but i am getting frustrated as well :-) Does anybody have a word 2010 macro that does not skip any field at all, i can't be the only one that is finding half-working solutions on the internet

thanks in advance

PS if you ask me for examples i have tried i will end up copy and pasting all my search results, so if you want to know what i have tried Google for "update all fields macro word 2010" :-)
PPS macro security is temporary switched off so the macro definitely runs
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2012
This should update all the fields:
Private Sub UpdateAllFields()
Dim oRange As Range
Dim oRange2 As Range
' Go through all story ranges in the document, including shapes,
' headers & footers.
For Each oRange In ActiveDocument.StoryRanges
    Set oRange2 = oRange 'set oRange2 to first range in story
        Set oRange2 = oRange2.NextStoryRange
    Loop Until oRange2 Is Nothing
Next oRange
End Sub

Open in new window


i really must be doing something wrong in my document. the macro indeed updates all fields, exect for the one containing the filename with the path added to it. it is in the footer of the document.

any idea?
Stacy BrownSenior Applications Administrator
The update all fields code that GrahamSkan posted should work for you.  Where are you placing the code? In a new module or in the "This document" module?  Are you saving the template as a .dotm file?  Try re-adding the field via Insert > Quick Parts > Field

In order for the macros to continue working you must save the file as either a .dotm or a .docm file.  

I don't normally do this, but try placing the code in the "ThisDocument" module.

In order for this to automatically fire upon Document Open and Close, you need to include an AutoOpen and an AutoClose macro that call the UpdateAllFields code (from GrahamSkan).  The AutoClose also needs to have a Save line included since the fields are updating..  Here is a screenshot of mine:  Code screenshot
I tried to attach at 2010 sample for you but it wouldn't allow the .docm extension or the .dotm extension.  I hope the screenshot is enough.
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial