Document Editing Problems

Insert a File Name Field in Every Word Footer Without Removing Content

Adam DavisAdam Davis Nov 22, 2026 868 views

Question details

Add a file name or full path field to every applicable Word footer without replacing existing content or duplicating fields.

Insert a File Name Field in Every Word Footer Without Removing Content
Product
Microsoft Word
Device & OS
not provided
Scenario
A document has multiple sections and may use linked, first-page, or even-page footers.
Observed behavior
Each applicable footer should display the file name while retaining its existing text; linked footers should inherit the field from the preceding section.
Before you start

Save the document so Word has a file name and path to display, and check whether it uses different first-page or even-page footers. The macro solution requires desktop Word with VBA enabled; run macros only from trusted sources.

Solution 1Recommended

Use a Word macro to add file name fields to existing footers

Use this method to process applicable footers across multiple sections while preserving their existing content.

The macro checks each existing footer for a FILENAME field anywhere in that footer. It skips linked footers because they inherit content from the previous section, and adds a separate paragraph before inserting a missing field.

1
Open the VBA editor

In desktop Word, open the document and select Developer > Visual Basic. If the Developer tab is hidden, open the VBA editor with Alt+F11.

2
Insert the macro

In the VBA editor, select Insert > Module and paste this code: Sub AddFileNameToFooters() Dim sec As Word.Section Dim foot As Word.HeaderFooter Dim fld As Word.Field Dim rng As Word.Range Dim found As Boolean Dim skipFooter As Boolean For Each sec In ActiveDocument.Sections For Each foot In sec.Footers If foot.Exists Then skipFooter = False If sec.Index > 1 Then skipFooter = foot.LinkToPrevious If Not skipFooter Then found = False For Each fld In foot.Range.Fields If fld.Type = wdFieldFileName Then found = True Exit For End If Next fld If Not found Then Set rng = foot.Range.Duplicate rng.SetRange foot.Range.End - 1, foot.Range.End - 1 rng.InsertBefore vbCr rng.Collapse wdCollapseEnd rng.Fields.Add Range:=rng, Type:=wdFieldFileName, Text:="\p", PreserveFormatting:=True End If End If End If Next foot Next sec End Sub

3
Run and review

Return to Word, select Developer > Macros, choose AddFileNameToFooters, and click Run. Review the first-page, even-page, and regular footers used by the document.

Use a Word macro to add file name fields to existing footers
Choose the displayed value: The \p switch includes the full path. For the file name only, replace Text:="\p" with Text:="" before running the macro. Existing FILENAME fields are left unchanged.
Free Microsoft Office alternative

Edit Word documents and footers with WPS Office

WPS Office is a free, lightweight alternative with a familiar editing interface and support for common Word formats, making it easy to move everyday documents between suites. The Word VBA macro described above must be run in Microsoft Word.

Edit document text and footer content in WPS WriterOpen and edit Microsoft Word DOC and DOCX filesWork in a familiar Office-style interfaceUse a lightweight suite for everyday document editing
microsoft office alternative - wps office

Frequently Asked Questions

How do I show the full path instead of just the file name?

Use the \p switch in the FILENAME field. In the manual Field dialog, select FileName and choose the option to add the path.

Why does the macro skip some footers?

A footer linked to the previous section inherits that footer's content. The macro edits the independent source footer instead of adding a field separately to the linked one.

Will the macro detect a file name that I typed as plain text?

No. It checks for FILENAME fields, not ordinary text. Review the footer content if a typed file name may already be present.

How can I update a file name field after saving the document under a new name?

Open the footer, select the field, and update it using Word's Update Field command. Check the displayed value after saving the document with its new name.