I search and change the text in the footer like this:
Sub 123()
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 xFooter In xSec.Footers
xFooter.Range.Select
Set xSelection = xDoc.Application.Selection
With xSelection.Find
.Text = "text1"
.Replacement.Text = "text2"
.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
After the macro works, several empty lines are added to the first page. How can I make the macro work from the second page of the document?
UPDATE: I described the problem incorrectly, it does not create rows, it adds an empty header.
UPDATE 2:
I solved the problem with the help of the code:
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Try the code below: