Finding and Replacing in Headers and Footers

Written by Allen Wyatt (last updated December 21, 2024)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, 2021, and Word in Microsoft 365


2

Eppa needs to replace a company name in a document. The name appears throughout the document, and also in the header and footer. The document has multiple sections. Eppa can use Find and Replace to replace within the document itself, but it won't make replacements in the headers and footers for some reason. So, Eppa wonders if there is some setting that will cause Find and Replace to make the necessary replacements in the header and footer at the same time it does so in the document.

This is a more involved question that it may, at first, appear. Using Word on a Microsoft 365 installation, doing a simple text replacement using Find and Replace did exactly what Eppa wanted—it replaced the text in the main document and in the headers and footers.

If Word does not replace in the headers and footers for some reason, then there is a two-pass approach you can try out. Let's say that your document has an old company name ("Harris Electric") and that you want to replace that with a new company name ("Davis Services"). Follow these steps:

  1. Press Ctrl+H. Word displays the Replace tab of the Find and Replace dialog box.
  2. In the Find What box, enter the old company name ("Harris Electric").
  3. In the Replace With box, enter the new company name ("Davis Services").
  4. Click Replace All. This replaces all the instances of the name in the main document, and Word displays a dialog box indicating how many replacements it made.
  5. Click OK to dismiss the information dialog box. (The Find and Replace dialog box should still be visible.)
  6. Display the Find tab.
  7. Click the Find In drop-down list. Word displays some options.
  8. Choose the Header and Footer option.
  9. Display the Replace tab.
  10. Click, again, on Replace All. This replaces all the instances of the name in the headers and footers. Word, again, displays a dialog box indicating how many changes were made.
  11. Click OK to dismiss the information dialog box.
  12. Click Close to dismiss the Find and Replace dialog box.

If you need to replace the company name in a lot of documents, then it may be better to use a macro. Here's an example of a macro that will make replacements in the main document and then in each header and footer in all the sections of the document:

Sub ReplaceInHeadersFooters()
    Dim sec As Section
    Dim hdr As HeaderFooter
    Dim ftr As HeaderFooter
    Dim rng As Range
    Dim findText As String
    Dim replaceText As String
    Dim StartMsg1 As String
    Dim StartMsg2 As String
    Dim EndMsg As String

    ' Set initial information
    StartMsg1 = "Enter the text to find:"
    StartMsg2 = "Enter the replacement text:"
    EndMsg = "Replacement completed in document, headers, and footers!"

    ' Set the text to find and replace
    findText = InputBox(StartMsg1, "Find Text")
    replaceText = InputBox(StartMsg2, "Replace Text")

    ' Replace in main document body
    Selection.HomeKey wdStory
    With Selection.Find
        .Text = findText
        .Replacement.Text = replaceText
        .Forward = True
        .Wrap = wdFindContinue
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    ' Replace in headers and footers for each section
    For Each sec In ActiveDocument.Sections
        ' Loop through headers
        For Each hdr In sec.Headers
            If hdr.Exists Then
                Set rng = hdr.Range
                With rng.Find
                    .Text = findText
                    .Replacement.Text = replaceText
                    .Forward = True
                    .Wrap = wdFindContinue
                    .Execute Replace:=wdReplaceAll
                End With
            End If
        Next

        ' Loop through footers
        For Each ftr In sec.Footers
            If ftr.Exists Then
                Set rng = ftr.Range
                With rng.Find
                    .Text = findText
                    .Replacement.Text = replaceText
                    .Forward = True
                    .Wrap = wdFindContinue
                    .Execute Replace:=wdReplaceAll
                End With
            End If
        Next
    Next
   MsgBox EndMsg, vbInformation
End Sub

Run the document and you can enter what you want to find and what you want to replace it with. If you need the finding and replacing to be case sensitive, then add the following to each iteration of the Find and Replace, just before the setting of the .Forward property:

        .MatchCase = True

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (7538) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, 2021, and Word in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Passing Parameters to Functions

Functions can be used to perform repetitive tasks and return values to your main program. You can also pass values to a ...

Discover More

Applying Styles and Removing Characters using Find and Replace

The Find and Replace capabilities of Word are very powerful, allowing you to accomplish more than one task at a time. ...

Discover More

Forcing the Date to the Next Wednesday

Working with today's date in Word is easy. Trying to manipulate dates to come up with a future one can be an entirely ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 365 applications with VBA programming. Written in clear terms and understandable language, the book includes systematic tutorials and contains both intermediate and advanced content for experienced VB developers. Designed to be comprehensive, the book addresses not just one Office application, but the entire Office suite. Check out Mastering VBA for Microsoft Office 365 today!

More WordTips (ribbon)

Pay Attention to Case when Searching for ASCII Codes

Word allows you to search for specific ASCII codes in a document. If you use codes to search for alphabetic characters, ...

Discover More

Getting Rid of Hidden Text in Many Files

Hidden text is a great boon if you want to make sure something doesn't show up on the screen or on a printout. If you ...

Discover More

Selectively Find and Replace Page Borders

Using Find and Replace you can both find and replace graphics in your document. Replacing graphics selectively is a bit ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is eight more than 0?

2026-01-07 13:48:03

Karen G

Thank you for this tip! This saved me a lot of time. I had a merged document of annual giving letters and each letter (1 page) had a footer date that did not get updated on the merge template. It took me a couple tries to get this to work but now I'm all set! I think I first tried it when I already had the "edit footer" open and the "find in" only wanted to work for the current page. When I closed the "edit footer" and tried again, it found and made all the footer replacements! Yay! thanks again!


2024-12-23 15:28:22

Kevin Swan

I'm not sure if this still works but I seem to remember that if you do a Ctrl-A (Select All) and then do the Find & Replace, it does the main document and the headers and footers. It might only work in draft view mode?


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.