Word

Update All Document Fields

Ease of Use

Easy

Version tested with

2003,2007,2010 

Submitted by:

gmaxey

Description:

Use this macro to effortlessly update "ALL" fields in a Microsoft Word Document. 

Discussion:

This macro takes seriously the challenge to update all fields in a document. Fields can be located nearly anywhere in a Word document and their location sometimes stumps the more simplistic attempts at updating fields. 

Code:

instructions for use

			

Public Sub UpdateAllFieldsOnSteroids() Dim rngStory As Word.Range Dim lngJunk As Long Dim oShp As Shape lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType For Each rngStory In ActiveDocument.StoryRanges 'Iterate through all linked stories Do On Error Resume Next rngStory.Fields.Update Select Case rngStory.StoryType Case 6, 7, 8, 9, 10, 11 If rngStory.ShapeRange.Count > 0 Then For Each oShp In rngStory.ShapeRange If oShp.TextFrame.HasText Then oShp.TextFrame.TextRange.Fields.Update End If Next End If Case Else 'Do Nothing End Select On Error GoTo 0 'Get next linked story (if any) Set rngStory = rngStory.NextStoryRange Loop Until rngStory Is Nothing Next End Sub

How to use:

  1. Copy the code above.
  2. Open Word.
  3. Hit Alt+F11 to open the Visual Basic Editor.
  4. In the Project Explorer on the left, select the Normal project and hit Insert-Module from the menu.
  5. Paste the code into the module window at the right of the VBE.
  6. Save the project.
  7. Close the VBE.
 

Test the code:

  1. Insert a new field into any document.
  2. Hit Tools-Macro-Macros and double-click UpdateAllFieldsOnSteroids.
 

Sample File:

UpdateAllFieldsOnSteroids.zip 17.3KB 

Approved by mdmackillop


This entry has been viewed 274 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express