MS Word is a peculiar beast and it should be remembered that, just because it comes out of the Microsoft stable, this doesn’t mean it works the same as MS Excel. There are some obscure reasons for this peculiarity but, rather than go into these in depth, I’ll limit the scope of this article to a specific question posed recently.
The question was:
“Why, when I insert a field code e.g. ‘filename’ at the end of the document does it not update with a new name or new version if I do “File>Save As”. The box stating “preserve formatting” is checked but it still does not change the stamp on the document.”
The answer to this perfectly reasonable question is that, as I already mentioned, MS Word does not act like MS Excel. In MS Excel, this action would have updated the fields automatically and quite happily. With MS Word, you would only be able to see the updates when you next re-open the file. Alternatively, if you want to see the change immediately, you need to refresh the document in some way, e.g. use Ctrl+A to select all and then press F9 to refresh. Huzzah! It is now updated.
There are other ways to do this as well, for instance, shifting to Print Preview and back and so on. Unfortunately SaveAs is just not one of these ways and, by default, the only time an MS Word document automatically updates field values is when you open it.
So, perhaps a macro? Of course, we all know and love macros, so here goes. Assuming you want this to be available to all of your MS Word documents, and not just the one you are currently editing then the code needs to be added to a new module in the VB Project Normal.
To do this, click on Alt+F11 to open the Visual Basic Editor (VBE) and select the Normal project from the Projects window (usually to be found on the left-hand side). Now press Alt+I+M, which will create a new module in the selected project. Once this is open, copy and paste the following code into your new module:
Sub updateAllFields() ActiveDocument.Fields.Update End Sub
At this point, I also recommend renaming the module from the default MS name, which is no doubt along the lines of “Module1” or something equally informative. Below the Projects window sits the Properties window. In this, click on the Name field and rename your new module to something more useful e.g. “MFieldUpdater”. Once you have done all of this you can close the VBE and return to MS Word.
Great – now you have your new macro to update fields, it’s in place, ready to be used in any document and you’re raring to go. So why not add a keyboard shortcut? No reason at all, it turns out…
To create your new keyboard shortcut click on Tools>Customize>Keyboard, scroll down to Macros, then select your new macro, so, using the current example, it will be called updateAllFields. (Have a look back at the first line of code if you’re not sure why this is so). Highlight the box marked Press new shortcut key and enter your chosen shortcut key combination e.g. Alt+U. Click on Assign, then Close and Close again.
Now if you press Alt+U your macro will update all fields in your active document. That’s it. Enjoy.