Word 2007 Macro That Removes Header and Footer?

Dear Experts,

I was wondering if someone would be kind enough to write me a simple Word 2007 Macro, which when run removes the header and footer from the word document that is open.

I hope this is not too much trouble. I will need help/advice on how to implement it, unfortunately I am not too great with coding in general.

Many Thanks,

Who is Participating?
A couple of points.

Firstly, this site is is intended to help by showing how to do it, not to do the work for you. However, this is a simple task and could be of interest to many.

Secondly, Word documents always have headers and footers. They can't be deleted. However they can be cleared of content.

Paste this code into a module of your template (probably the Normal template). Put the text cursor in the code and press F5 to run it.
Sub ClearHeadersText()
    Dim hdr As HeaderFooter
    Dim ftr As HeaderFooter
    Dim sec As Section
    Dim rng As Range
    For Each sec In ActiveDocument.Sections
        For Each hdr In sec.Headers
            Set rng = hdr.Range
        Next hdr
        For Each ftr In sec.Footers
            Set rng = ftr.Range
        Next ftr
    Next sec
End Sub

Open in new window

ouch_mybrain_Author Commented:
Brilliant, thank you. it works. If it wasn't simple then I would not have asked, but point taken for future reference. Thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.