VBA & Macro Problems

Fix a Word 2016 Macro That Inserts Footer Content in the Header

Ayan MasoodAyan Masood Nov 22, 2026 868 views

Question details

Correct a recorded Word macro so header and footer content goes into the intended areas.

Fix a Word 2016 Macro That Inserts Footer Content in the Header
Product
Microsoft Word 2016
Device & OS
not provided
Scenario
A user records a macro to add content to a document's header and footer.
Observed behavior
Content intended for the footer may be inserted into the header because recorded navigation between header and footer layers is unreliable.
Before you start

Identify which document section and header or footer type the macro should change. If you plan to edit VBA, make sure the Developer tab is available and review the recorded macro's existing navigation commands.

Solution 1Recommended

Edit the Macro to Use Explicit Header and Footer Ranges

Use explicit VBA ranges when the macro needs to place different content in the header and footer.

The example targets the primary header and footer in the document's first section. It replaces their existing contents, so adapt it if you need to preserve text, formatting, page numbers, or fields.

1
Open the VBA editor

In Word, select Developer > Visual Basic. Open the module containing the recorded macro in the Project pane.

2
Replace recorded navigation

Replace the recorded header and footer navigation and insertion commands with explicit range assignments, adapting the text as needed: ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = "Header text" ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Text = "Footer text"

3
Save and test the macro

Save the document as a Word Macro-Enabled Document (.docm), then select Developer > Macros, choose the macro, and select Run. Check the first section's header and footer.

Edit the Macro to Use Explicit Header and Footer Ranges
Check section and page settings: Different first-page or odd-and-even-page settings use separate header and footer types. Later sections can also be linked to previous sections, so adjust the VBA targets and links if your document uses those features.
Free Microsoft Office alternative

Create Documents With Headers and Footers in WPS Writer

WPS Office is a free, lightweight alternative with a familiar interface and Microsoft Office format compatibility, making it easier to move existing documents into WPS Writer. It does not fix Word's Macro Recorder behavior.

Add and edit headers and footers in WPS WriterOpen and edit Microsoft Word DOC and DOCX filesWork with a familiar document-editing interfaceUse a lightweight office suite available for free
microsoft office alternative - wps office

Frequently Asked Questions

Why does my recorded macro put footer text in the header?

Word's Macro Recorder may not reliably navigate between header and footer layers. Edit the macro in Developer > Visual Basic to reference the intended header and footer ranges directly.

Will the VBA example preserve existing page numbers?

No. Assigning text to a header or footer's Range.Text replaces its existing contents, including fields such as page numbers. Adapt the macro if those contents must be preserved.

How do I handle a different first-page header or footer?

Check the Different First Page setting in Word's header and footer tools. In VBA, target the first-page header or footer type rather than wdHeaderFooterPrimary when that is the area you need to change.

Can I avoid using a macro for repeated headers and footers?

Yes. Add the content through Insert > Header and Insert > Footer, then use File > Save As to save a Word Template (.dotx) for new documents.