Document Editing Problems

Automatically Update a File Path Field in Microsoft Word on Open or Save

Natalie TaylorNatalie Taylor Nov 13, 2026 868 views

Question details

The user wants a Word document's file path field to update automatically when the document opens or saves, without manually pressing F9.

Automatically Update a File Path Field in Microsoft Word on Open or Save
Product
Microsoft Word desktop
Device & OS
not provided
Scenario
A document displays its file path, potentially in a footer, and needs to reflect its current name and location after opening or saving.
Observed behavior
The displayed path remains outdated until the field is manually updated or refreshed through print preview.
Before you start

Confirm that the path is a FILENAME field with the \p switch, rather than ordinary typed text. Use desktop Word and save the document as a Word Macro-Enabled Document (.docm); run macros only in documents you trust and where your organization's security policy permits them.

Solution 1Recommended

Update file path fields automatically when the Word document opens

Use a document-open event to refresh fields in the main document, headers, and footers without selecting them individually.

Word displays a full file path using the FILENAME field with the \p switch. Updating only ActiveDocument.Fields does not reliably cover footer fields, so this procedure also traverses the document's other story ranges.

1
Check the file path field

Right-click the displayed path and choose Toggle Field Codes. The field should read FILENAME \p inside Word's field braces. If the path is plain text, replace it through Insert > Quick Parts > Field > FileName and select Add path to filename, where available.

2
Add a reusable field-update macro

Open the Visual Basic Editor through Developer > Visual Basic. Select your document's VBA project, choose Insert > Module, and paste: Public Sub RefreshPathFields(ByVal doc As Document) Dim story As Range Dim currentRange As Range For Each story In doc.StoryRanges Set currentRange = story Do currentRange.Fields.Update Set currentRange = currentRange.NextStoryRange Loop Until currentRange Is Nothing Next story End Sub

3
Add the document-open event

In the same document project, double-click ThisDocument under Microsoft Word Objects and paste: Private Sub Document_Open() RefreshPathFields Me End Sub

4
Save and test the document

Choose File > Save As and select Word Macro-Enabled Document (*.docm). Close and reopen the document, allowing macros only if the file is trusted. Check the displayed path in the footer or other location.

Opening updates fields but does not save the changes: This event refreshes fields in the open document. Save afterward if you want the updated field results stored in the file. The helper updates all fields in the traversed ranges, not just file path fields.
Free Microsoft Office alternative

Use WPS Writer for everyday Word document editing

WPS Writer is a free, lightweight alternative with a familiar interface and support for Microsoft Word formats, making it easy to move everyday document editing to WPS. It is not a fix for Word's VBA save events; verify file path field behavior and macro support before migrating an automated document.

Open and edit Microsoft Word .doc and .docx documents.Use a familiar interface for an easy transition from Word.Edit document headers and footers used for file location information.Choose a lightweight, free option for everyday document work.
QA img-9

Frequently Asked Questions

Why does my Word file path still show the old folder after Save As?

A FILENAME \p field stores a displayed result that may not refresh immediately after Save As. Right-click the field and choose Update Field, or use a save-command macro that updates fields after the new name and location have been saved.

Why doesn't selecting the whole document and pressing F9 update the footer path?

Selecting the document body does not necessarily select fields in headers and footers. Double-click the footer, select its path field, and press F9, or right-click it and choose Update Field. For automation, update footer ranges or traverse the document's story ranges.

Can I put Document_BeforeSave in ThisDocument?

No. Word's ThisDocument module does not expose that event. Word has an application-level DocumentBeforeSave event, which requires a WithEvents application object and runs before the save. For a new Save As path, use a workflow that refreshes the field after saving.

Do I have to save the document as a .docm file?

Yes, if the VBA code is stored inside the document. Choose File > Save As > Word Macro-Enabled Document (*.docm). A .docx file cannot retain VBA code; a macro-enabled template (.dotm) is another option for a managed template workflow.

Can this work in Word for the web or without enabling macros?

Word for the web does not run VBA macros. Open the document in desktop Word to use these procedures. If macros are blocked by your organization, use Update Field manually in desktop Word or ask your administrator about an approved automation approach.