Capture a Save As File Name in Microsoft Word VBA
Question details
The user wants a Word document footer to reflect its file name automatically when the document is saved or saved under a new name.

- Product
- Microsoft Word VBA
- Device & OS
- not provided
- Scenario
- A user enters a file name in Word's built-in Save As dialog and wants that name displayed in the document footer.
- Observed behavior
- Word's DocumentBeforeSave event occurs before the Save As dialog completes, so it does not provide the newly entered file name at that point.
Check whether the footer already contains a FileName field and whether the document has been saved at least once. To use the macro workflow, enable the Developer tab and allow macros from a trusted source.
Update the footer after Save As with a VBA macro
Use this workflow when users can run a macro instead of the standard Save As command.
Word's DocumentBeforeSave event runs before the built-in Save As dialog finishes, so it cannot read the name the user subsequently enters. This macro lets the dialog save the document first, updates existing footer fields, and then saves the updated fields.
The macro only runs when explicitly invoked; it does not automatically intercept every Save or Save As action.
Open the footer, then choose Insert > Quick Parts > Field > FileName and select OK. Add the field to any separate footers that need to show the name.
Choose Developer > Visual Basic, insert a standard module in Normal.dotm or a trusted macro-enabled template, and paste: Sub SaveAsAndUpdateFooter() Dim doc As Document Dim sec As Section Dim ftr As HeaderFooter Set doc = ActiveDocument If Dialogs(wdDialogFileSaveAs).Show <> -1 Then Exit Sub For Each sec In doc.Sections For Each ftr In sec.Footers If ftr.Exists Then ftr.Range.Fields.Update Next ftr Next sec doc.Save End Sub
Choose Developer > Macros, select SaveAsAndUpdateFooter, and click Run. Enter the name in the Save As dialog and save; the macro then updates the footer fields and saves again.

Insert and manually update a FileName field
Use a Word field without VBA when manually refreshing the footer is acceptable.
Edit Word Documents with WPS Writer
WPS Office is a free, lightweight alternative with a familiar interface for editing documents and moving between office suites. It does not fix Microsoft Word's VBA save events.

Frequently Asked Questions
Why can't DocumentBeforeSave read the new Save As name?
The event occurs before Word completes the Save As dialog. The user's new name is available after the document has been saved under that name.
How do I put the document name in a Word footer?
Double-click the footer, then choose Insert > Quick Parts > Field > FileName. After saving the document, right-click the field and select Update Field if it needs refreshing.
Will the macro run when I use the regular Save As command?
No. Run SaveAsAndUpdateFooter from Developer > Macros to use the workflow shown here. It does not automatically replace Word's standard command.
Does the macro create a FileName field in every footer?
No. Insert the FileName field in the relevant footers first. The macro updates existing fields after the Save As dialog completes.




