« Google Suggest | Main| Candy Canes »

Refresh Fields in Microsoft Word

Bookmark : del.icio.us  Technorati  Digg This  Add To Furl  Add To YahooMyWeb  Add To Reddit  Add To NewsVine 

The concept of having page numbers and other fields in Word to dynamically display information works and sounds great. The only drawback is getting the information to stay up to date. Yes, there is the F9 feature that refreshes all the selected fields. Having to remember to select all the text and then press F9 is not bad. But the headers and footers are not selected so they do not get updated. Each different header needs to be updated individually. This macro will update all the fields in each section of the active document.


Create Macro

  1. Select Tools - Macro - Macros from the menu bar
  2. Enter RefreshAllFields for the 'Macro Name'
  3. Select 'Normal.doc' for 'Macros in'
  4. Select 'Create' option
  5. Refres All Fields Macro
  6. Copy the following text between Sub and End Sub
  7. Paste into Visual Basic Editor

Sub RefreshAllFields()
'
' RefreshAllFields Macro
'
'
For i = 1 To ActiveDocument.Sections.Count
If Not ActiveDocument.Sections(i).Headers Is Nothing Then
For h = 1 To ActiveDocument.Sections(i).Headers.Count
x = ActiveDocument.Sections(i).Headers(h).Range.Fields.Update()
Next h
End If
x = ActiveDocument.Range.Fields.Update()
If Not ActiveDocument.Sections(i).Footers Is Nothing Then
For f = 1 To ActiveDocument.Sections(i).Footers.Count
x = ActiveDocument.Sections(i).Footers(f).Range.Fields.Update()
Next f
End If
Next i
End Sub


Run Macro

  1. Select Tools - Macro - Macros from the menu bar
  2. Select RefreshAllFields for List of macros
  3. Sit back and watch

I use this macro so often that I added it to my personal toolbar that is always displayed in every document.

Comments

1 - Thanks very much for the macro! Came in very handy.

2 - I suppose I misunderstand the purpose of this macro.

I have tables in my document that give an overview of each chapter. They contain fields linked to bookmarks, which display the page number in the table. These page numbers don't update as I edit the document, so I have to go to each "overview" table and manually right-click and select "update field."

This macro doesn't update those fields. Emoticon

3 - Tuck,

the page numbers won't update as you edit the document. They will update when you run the macro. It's automates the right-clicking and selecint "update field" that you are doing.

I've tried other similar scripts but somehow they all mess up some references. This seems to work the best so far.

4 - Thanks for this macro, worked to a tea. Emoticon

5 - Do you know a way to run this marco automatically when the Word document opens?

Alex

6 - I am sure that there is a way, but I have not tried it.

7 - Amazing! macro. This saved me a days worth of work! Whew!!! Super!

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)