How to Use VBA to Update All Fields in Word
🔍 WiseChecker

How to Use VBA to Update All Fields in Word

Manually updating every field in a long Word document—such as table of contents entries, cross-references, page numbers, and indexes—can take minutes and is easy to forget. Word’s built-in field update commands only work on the current selection or the entire document when you print or close the file. This article explains how to write and run a simple VBA macro that updates all fields in the active document with a single click, saving time and preventing outdated references.

Key Takeaways: Automating Field Updates With a VBA Macro

  • Alt + F11: Opens the VBA editor where you paste the macro code
  • Fields.Update method: The single command that refreshes every field in the document
  • Alt + F8: Opens the Macro dialog to run your custom macro

What a VBA Field-Update Macro Does and What You Need Before Using It

A VBA macro is a small program that automates repetitive tasks inside Word. The macro for updating all fields uses the Fields.Update method, which iterates through every field in the active document and forces it to recalculate its value. This includes fields for the table of contents, cross-references, page numbers, indexes, formulas, and custom document properties.

Before you can use the macro, you need to enable the Developer tab in Word. This tab provides access to the VBA editor and macro tools. You also need to save your document in a format that supports macros—either the .docm (macro-enabled document) or .dotm (macro-enabled template) extension. Standard .docx files cannot store VBA code.

The macro works on the entire document, including headers, footers, footnotes, endnotes, and text boxes. It does not require any programming experience because you only need to copy, paste, and run the code provided in this article.

Enable the Developer Tab

If the Developer tab is not visible on the ribbon, follow these steps:

  1. Open Word Options
    Click File > Options.
  2. Customize the Ribbon
    In the Word Options dialog, select Customize Ribbon on the left.
  3. Check Developer
    Under Main Tabs on the right, check the box next to Developer. Click OK.

How to Write and Run the VBA Macro to Update All Fields

Follow these steps to insert the macro into your document and execute it. You only need to do this once per document. After that, you can run the macro whenever you need to refresh all fields.

Step 1: Open the VBA Editor

  1. Press Alt + F11
    The VBA editor window opens. It shows a project explorer on the left and a code pane on the right.
  2. Insert a new module
    In the menu bar, click Insert > Module. A new module appears under the Normal project or under your document’s project.

Step 2: Paste the Macro Code

  1. Copy the code below
    Select and copy the following VBA code:
    Sub UpdateAllFields()
        Dim fld As Field
        For Each fld In ActiveDocument.Fields
            fld.Update
        Next fld
        MsgBox "All fields have been updated.", vbInformation, "Field Update Complete"
    End Sub
  2. Paste into the module
    Click inside the blank code pane and press Ctrl + V to paste the code.
  3. Close the VBA editor
    Click the X in the top-right corner of the VBA editor window to return to Word.

Step 3: Save the Document as Macro-Enabled

  1. Click File > Save As
    Choose a location and enter a file name.
  2. Select the correct format
    In the Save as type dropdown, choose Word Macro-Enabled Document (docm). Click Save.

Step 4: Run the Macro

  1. Press Alt + F8
    The Macro dialog opens, listing all available macros.
  2. Select UpdateAllFields
    Click the macro named UpdateAllFields, then click Run. A message box confirms that all fields have been updated.

Common Mistakes and Limitations When Using the Field-Update Macro

Even a simple macro can cause confusion if you are not aware of its behavior and constraints. The following issues are the most frequent among business users.

The Macro Does Not Appear in the Macro List

If you cannot see UpdateAllFields when you press Alt + F8, the macro was pasted into the wrong location. Open the VBA editor again (Alt + F11) and confirm that the code is inside a module under the Normal project or under your document’s project. A macro placed inside a document event or a class module will not appear in the Macro dialog. Right-click the module in the Project Explorer and select Remove to delete it, then re-insert a standard module and paste the code again.

The Document Is Saved as .docx and the Macro Is Lost

When you close a .docx file that contains a macro, Word silently removes the VBA code. Always save the file as .docm after adding the macro. If you accidentally saved as .docx, re-paste the macro code and save again using the correct format. To check the current format, look at the file extension in Windows File Explorer or click File > Info and inspect the file type listed under Properties.

The Macro Updates Fields But Breaks Table of Contents Page Numbers

The macro updates every field exactly once. For a table of contents (TOC), a single update may not recalculate page numbers if the TOC field itself requires two passes. To fix this, run the macro twice in a row. Alternatively, right-click the TOC and select Update Field, then choose Update page numbers only or Update entire table. For automated two-pass updates, modify the macro to call ActiveDocument.TablesOfContents(1).Update inside a loop.

The Macro Stops or Returns an Error on Protected Documents

If the document has editing restrictions or is marked as final, the macro cannot modify fields. Click Review > Restrict Editing and stop protection. If the document is marked as final, click the Marked as Final bar at the top and select Edit Anyway. After removing restrictions, run the macro again.

Macro-Enabled Document vs Standard Document: Field Update Behavior

Item .docm (Macro-Enabled) .docx (Standard)
VBA macro storage Stores macros inside the file Cannot store macros
Field update method Run custom VBA macro to update all fields Must use Ctrl + A then F9, or rely on Print Preview
Security warning on open May show a security warning; user must enable macros No macro warning
File sharing Some email servers block .docm attachments Widely accepted by email filters
Batch field update speed One-click macro updates hundreds of fields in seconds Manual selection and F9 can take several minutes for large documents

You can now update every field in a Word document by pressing Alt + F8 and selecting the UpdateAllFields macro. Store the macro in your Normal.dotm template so it is available in all future documents. For documents that require frequent field refreshes, consider assigning the macro to a custom keyboard shortcut via File > Options > Customize Ribbon > Keyboard Shortcuts > Macros.