If statement causing Word crash

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top