G
Gazzit
I am trying to replace header text in a document that has several sections.
My code below causes Word to crash. If I remove the if statement, the replace
does not cycle through the headers.
Sub Macro4()
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
For Each Section In ActiveDocument.Sections
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Facilitator Guide"
.Replacement.Text = "Participant Workbook"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
If Not ActiveDocument.Sections.Last Then
ActiveWindow.ActivePane.View.NextHeaderFooter
End If
Next Section
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
My code below causes Word to crash. If I remove the if statement, the replace
does not cycle through the headers.
Sub Macro4()
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
For Each Section In ActiveDocument.Sections
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Facilitator Guide"
.Replacement.Text = "Participant Workbook"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
If Not ActiveDocument.Sections.Last Then
ActiveWindow.ActivePane.View.NextHeaderFooter
End If
Next Section
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub