N
Neil Humphries
We have standardized headers in 200 documents. The user will select a subset
of the documents for a particular project. I want to be able to automate the
replacement all the placeholder text in the header with project specific
text. In each header there are 8 pieces of placeholder text and 10 pieces of
fixed text.
Since the placeholder text is consistent, I want to do a find and replace on
the placeholder text. I have an array of find/replace pairs. The code below
runs, but doesn't change the header contents.
What am I not doing or what am I doing wrong?
Sub FindandReplaceHeader()
For I = 0 To UBound(arrfindreplace, 2)
'clear find and replace fields
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
End With
With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
With Selection.Find
' .Replacement.Highlight = True
.Text = arrfindreplace(0, I)
.Replacement.Text = arrfindreplace(1, I)
.Forward = True
.Wrap = wdFindContinue
.MatchCase = False
.MatchWholeWord = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next
End Sub
of the documents for a particular project. I want to be able to automate the
replacement all the placeholder text in the header with project specific
text. In each header there are 8 pieces of placeholder text and 10 pieces of
fixed text.
Since the placeholder text is consistent, I want to do a find and replace on
the placeholder text. I have an array of find/replace pairs. The code below
runs, but doesn't change the header contents.
What am I not doing or what am I doing wrong?
Sub FindandReplaceHeader()
For I = 0 To UBound(arrfindreplace, 2)
'clear find and replace fields
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
End With
With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
With Selection.Find
' .Replacement.Highlight = True
.Text = arrfindreplace(0, I)
.Replacement.Text = arrfindreplace(1, I)
.Forward = True
.Wrap = wdFindContinue
.MatchCase = False
.MatchWholeWord = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next
End Sub