Share via

Assistance Required for Removing Header and Footer References in Word Document XML

mura 0 Reputation points
2025-03-14T07:01:10.1533333+00:00

I hope this message finds you well. I am reaching out to seek assistance with an issue I am experiencing in Microsoft Word 2019 Home Edition. As a non-native English speaker, I appreciate your understanding and patience.

My goal is to clear all headers and footers from my Word document without removing section breaks, as these are essential for maintaining the document's layout in portrait orientation. While I have attempted various methods that visually remove headers and footers from the pages, the corresponding <w:headerReference> tags remain in the document's XML structure.

The only solution I have found so far involves deleting section breaks and then using the "Remove Header/Footer" option, which is not ideal as I need to preserve the section breaks for layout purposes.

Could you please provide guidance or a solution that allows me to remove these XML references while retaining the section breaks? Your assistance in resolving this matter would be greatly appreciated.

Thank you for your support.

Microsoft 365 and Office | Development | Other

1 answer

Sort by: Most helpful
  1. Ilgar Zarbaliyev 116 Reputation points MVP
    2025-03-26T06:58:18.6533333+00:00

    Here's a precise way to remove all headers and footers (including <w:headerReference> and <w:footerReference> tags) without deleting section breaks in Microsoft Word 2019.

    Solution: Use Word’s "Open XML" View to Remove Header/Footer References

    Since you want to preserve section breaks and remove only the header/footer references from the document XML, follow these steps:


    Option 1: Use a Macro to Clean All Header/Footer References

    You can run a VBA macro that clears all headers and footers from each section, and ensures the XML references are removed too.

    VBA Macro:

    1. Press Alt + F11 to open the VBA editor.

    Insert a new module: Insert > Module.

    Paste the code below:

    Sub RemoveHeadersAndFootersKeepSections()
        Dim sec As Section
        For Each sec In ActiveDocument.Sections
            With sec.Headers(wdHeaderFooterPrimary)
                .Range.Delete
            End With
            With sec.Footers(wdHeaderFooterPrimary)
                .Range.Delete
            End With
            With sec.Headers(wdHeaderFooterFirstPage)
                .Range.Delete
            End With
            With sec.Footers(wdHeaderFooterFirstPage)
                .Range.Delete
            End With
            With sec.Headers(wdHeaderFooterEvenPages)
                .Range.Delete
            End With
            With sec.Footers(wdHeaderFooterEvenPages)
                .Range.Delete
            End With
        Next sec
    End Sub
    

    Run the macro: Press F5 or Run from the toolbar.

    This clears all types of headers and footers for every section while keeping section breaks intact. It also removes the header/footer references in the Open XML structure.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.