Skip to main content

Kutools for Office โ€” One Suite. Five Tools. Get More Done.

How to auto update field codes when reopen a Word document?

Author Sun Last modified

In Word document, we can insert the document name by using the fields, but if the document has been renamed, the file name filed cannot be updated automatically. In this tutorial, I introduce the way to auto update all field codes after reopening the document in Word.

Auto update field codes when reopen in Word


Auto update field codes when reopen a Word document

In Word, there is no built-in function can update the inserted fields, except the VBA code.

1. Press Alt + F11 keys to enable Microsoft Visual Basic for Applications window, double click ThisDocument in the left pane to open the ThisDocument (Code) window.

2. Copy and paste below code to the ThisDocument (Code) window.

VBA: Refresh field codes when reopen the document

Sub AutoOpen()
'UpdatebyExtendoffice20180830
    Dim xRange As Range
    Dim xFiled As Field
    For Each xRange In ActiveDocument.StoryRanges
        For Each xFiled In xRange.Fields
            xFiled.Update
        Next
    Next
End Sub

VBA pasted into the ThisDocument (Code) window

3. Click Save button to save the code in Microsoft Visual Basic for Applications window, a Microsoft Word dialog pops out, click No to go to the Save As dialog.
Save As dialog box

4. In the Save As dialog box, select a folder to save the document, name it as you need, select Word Macro-enabled Document from the Save as type drop-down, and then click the Save button. See screenshot:
Field codes updated automatically

From now on, every time you open the Macro-enable document, all field codes will be updated automatically.
Enable all macros (not recommended; potentially dangerous code can run) option checked in the Trust Center dialog

Note: Make sure the Enable all macros (not recommended; potentially dangerous code can run) option is checked in Trust Center dialog (Click File > Options > Trust Center > Macro Settings).
doc auto update fields when open 5

Tabbed Browsing & Editing for Multiple Word Documents/Excel Workbooks, Just Like in Chrome and Edge!

Just like browsing multiple webpages in Chrome, Safari and Edge, Office Tab lets you open and manage multiple Word documents or Excel workbooks in one Word window or Excel window. Switching between documents or workbooks is now simple with a click on their tabs!

Try Office Tab for free now!

Best Office Productivity Tools

Kutools for Word - Elevate Your Word Experience with Over 100 Remarkable Features!

๐Ÿค– Kutools AI Features: AI Assistant / Real-Time Assistant / Super Polish (Preserve Format) / Super Translate (Preserve Format) / AI Redaction / AI Proofread...

๐Ÿ“˜ Document Mastery: Split Pages / Merge Documents / Export Selection in Various Formats (PDF/TXT/DOC/HTML...) / Batch Convert to PDF...

โœ Contents Editing: Batch Find and Replace across Multiple Files / Resize All Pictures / Transpose Table Rows and Columns / Convert Table to Text...

๐Ÿงน Effortless Clean: Sweap away Extra Spaces / Section Breaks / Text Boxes / Hyperlinks / For more removing tools, head to the Remove group...

โž• Creative Inserts: Insert Thousand Separators / Check Boxes / Radio Buttons / QR Code / Barcode / Multiple Pictures / Discover more in the Insert group...

๐Ÿ” Precision Selections: Pinpoint Specific Pages / Tables / Shapes / Heading Paragraphs / Enhance navigation with more Select features...

โญ Star Enhancements: Navigate to Any Location / Auto-Insert Repetitive Text / Toggle Between Document Windows / 11 Conversion Tools...

๐ŸŒ Supports 40+ Languages: Use Kutools in your preferred language โ€“ supports English, Spanish, German, French, Chinese, and 40+ others!

Kutools and Kutools Plus tabs on the Word Ribbon
๐Ÿ‘‰ Want to try these features? Download Kutools for Word now! ๐Ÿš€
 

โœจ Kutools for Office โ€“ One Installation, Five Powerful Tools!

Includes Office Tab Pro ยท Kutools for Excel ยท Kutools for Outlook ยท Kutools for Word ยท Kutools for PowerPoint

๐Ÿ“ฆ Get all 5 tools in one suite | ๐Ÿ”— Seamless integration with Microsoft Office | โšก Save time and boost productivity instantly

Best Office Productivity Tools

Kutools for Word - 100+ Tools for Word