Word 2007 Macro That Removes Header and Footer?

Posted on 2011-05-10
Last Modified: 2012-05-11
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,

Question by:ouch_mybrain_
    LVL 76

    Accepted Solution

    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


    Author Closing Comment

    Brilliant, thank you. it works. If it wasn't simple then I would not have asked, but point taken for future reference. Thanks.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Title # Comments Views Activity
    PDF to Word 25 78
    Access 2016 VB code 9 69
    Using columns on multiple pages on MS Word. 23 27
    Check version 13 38
    If you work with Word a lot, you probably use styles. If you use styles a lot, you've probably balled your fist more often than not when working with the ribbon. In Word 2007/2010, one of the things that I find missing when using styles is a quic…
    Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
    This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
    This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now