Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Deleting All Headers and Footers.
Written by Allen Wyatt (last updated February 5, 2022)
This tip applies to Word 97, 2000, 2002, and 2003
If you work with documents you receive from other people, one of the tasks you may routinely need to do is delete all the headers and footers in the documents. One way to do this is to simply select the various headers and footers and delete them, but if the document contains many sections, doing so can be very time consuming. (Particularly if you consider that each section can have up to three different headers and footers.)
Repetitious, time-consuming tasks are always a prime candidate for macros; this is no exception. The following macro will zip right through each section of a document, deleting all the headers and footers that have been defined.
Sub RemoveHeadAndFoot() Dim oSec As Section Dim oHead As HeaderFooter Dim oFoot As HeaderFooter For Each oSec In ActiveDocument.Sections For Each oHead In oSec.Headers If oHead.Exists Then oHead.Range.Delete Next oHead For Each oFoot In oSec.Footers If oFoot.Exists Then oFoot.Range.Delete Next oFoot Next oSec End Sub
This macro is very powerful—it doesn't ask if you want to proceed, nor does it consider what may be included in the headers and footers. It simply deletes them all, leaving your document with none. If you regularly process quite a few documents, you can easily assign the macro to a toolbar button, menu item, or shortcut key.
Note:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1777) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Deleting All Headers and Footers.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
Need to get headers and footers from one document to another? You can use the steps in this tip to help make quick work ...
Discover MoreWhen you print a document, does the position of the page footer seem to move left and right? This could have to do with ...
Discover MoreNeed some specific text to appear just below the end of the text on the last page of your document? You can accomplish ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2022-02-24 11:58:16
Melissa Lalande
The macro worked very well when I was using Microsoft 2016, but ever since we switched to Microsoft 365 it stopped working. There is an error message saying that there is a compile errer in hidden module and gives us this link from the help:
(see Figure 1 below)
https://docs.microsoft.com/en-us/office/vba/Language/Reference/User-Interface-Help/compile-error-in-hidden-modulemodule-name
is there anyway to adapt it for Microsoft 365?
thank you
Melissa
Figure 1. Error message from macro on Word 365 64 bit
Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments