VBA & Macro Problems

Capture a Save As File Name in Microsoft Word VBA

Nimra MalikNimra Malik Nov 25, 2026 869 views

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.

Capture a Save As File Name in Microsoft Word VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Insert the file name field

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.

2
Add the macro

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

3
Run the Save As workflow

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.

Update the footer after Save As with a VBA macro
Scope of this workflow: Canceling the dialog exits the macro. A separate solution is needed to cover ordinary Save commands or enforce the workflow for every document.
Free Microsoft Office alternative

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.

Edit document footers in WPS WriterOpen and edit Microsoft Word DOC and DOCX filesUse a familiar interface for everyday document workMove existing documents to a lightweight office suite
microsoft office alternative - wps office

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.