Automatically Update a File Path Field in Microsoft Word on Open or Save
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.

- 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.
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.
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.
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.
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
In the same document project, double-click ThisDocument under Microsoft Word Objects and paste: Private Sub Document_Open() RefreshPathFields Me End Sub
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.
Refresh the file path after Word's Save and Save As commands
Use save-command macros when the displayed path must reflect a new filename or folder immediately after saving.
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.

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.




