Finding and replacing text in a Word document, including headers and footers

Usually, the Find & Replace feature can help locate and replace specific text in the content, headers, and footers of a Word document simultaneously. Have you ever tried to find and replace text only in the headers and footers of a Word document? Or perhaps to find and replace multiple different texts simultaneously in one Word document or across multiple documents? This guide demonstrates some methods to accomplish these tasks.

Find and replace the same text in a Word document using the Find and Replace feature

It’s easy to use the Find and Replace feature in a Word document.

1. Open the document containing the text you want to replace, then press Ctrl + H to open the Find and Replace dialog.

2. In the Find and Replace dialog, under the Replace tab, enter the old and new text separately in the Find what and Replace with boxes, then click the Replace All button. See screenshot:

Finding and replacing text in a Word document, including headers and footers

Finding and replacing text in a Word document, including headers and footers

Note: You can click the More button to find additional search options as needed.

3. Then, a dialog box pops up to let you know the number of replacements that have been made. Click OK to finish.


Only find and replace the same text in the headers and footers using VBA code

If you only want to find and replace in the headers and footers of the document, the method in this section can be useful.

1. Open the document where you will find and replace text in the headers and footers, then press Alt + F11 to open the Microsoft Visual Basic for Application window.

2. In the Microsoft Visual Basic for Application window, click Insert > Module, then copy the VBA code below into the Module window.

VBA Code: Only find and replace text in the header and footer

Sub FindAndReplaceOfHeaderAndFooter()
‘Update by Extendoffice 20190805
Dim xDoc As Document
Dim xSelection As Selection
Dim xSec As Section
Dim xHeader As HeaderFooter
Dim xFooter As HeaderFooter
On Error Resume Next
Set xDoc = Application.ActiveDocument
For Each xSec In xDoc.Sections
For Each xHeader In xSec.Headers
xHeader.Range.Select
Set xSelection = xDoc.Application.Selection
With xSelection.Find
.Text = “I’ve found header text” ‘Enter the old header text here!
.Replacement.Text = “I’ve found header text” ‘Enter the new header text here!
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Next xHeader
For Each xFooter In xSec.Footers
xFooter.Range.Select
Set xSelection = xDoc.Application.Selection
With xSelection.Find
.Text = “I’ve found footer text” ‘Enter the old footer text here!
.Replacement.Text = “I’ve found footer text” ‘Enter the new footer text here!
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Next xFooter
Next xSec
xDoc.ActiveWindow.ActivePane.Close
If xDoc.ActiveWindow.View.SplitSpecial = wdPaneNone Then
xDoc.ActiveWindow.View.Type = wdPrintView
Else
xDoc.ActiveWindow.View.Type = wdPrintView
End If
xDoc.Activate
End Sub

Note: In the code, please replace “Find header text” and “Find footer text” with the text you want to find in the header and footer, and replace “I’ve found header text” and “I’ve found footer text” with the new header and footer text.

3. Press F5 to run the code. Then, the specific texts in the header and footer will be replaced with the new text.

Finding and replacing different texts simultaneously using a fantastic feature

The Batch Find and Replace feature of Kutools for Word can easily find and replace different texts in a single document or across multiple documents at the same time.

1. Before applying this feature, take a few minutes to download and install it first.

2. Launch the Microsoft Word application, click on Kutools Plus > Batch Find and Replace.

In the Batch Find and Replace window, you need to do the following.

2.1 Click the Add File or Add Folder button to add the document in which you want to find and replace text.

2.2 Click the Add Row button to insert the search and replace fields. If you want to find and replace three different texts at the same time, create three rows.
2.3 In each row, enter the existing text you will replace with new text in the Find column, then enter the new text in the Replace column.
2.4 Specify the search type for each row.
2.5 In the Look in column, select the location to apply the find and replace. It includes Main document, Header, and Footer in this section. You can select one, two, or all of them based on your needs.
2.6. Click the Replace button to start the operation. See screenshot:

Afterward, all specific texts will be replaced in the selected documents.

We will be happy to hear your thoughts

Leave a reply

Gotkey.net
Logo
Compare items
  • Total (0)
Compare
0
Shopping cart