I have a Word document with 4 sections. The following code works, but is finding and replacing in the entire document rather than only in Section 3 as I wish. Any suggestions are greatly appreciated.
You don't know what you don't know...
Code:
Sub PrefixPipe()
Dim vFindText As Variant
Dim vReplText As Variant
Dim sFindText As String
Dim sReplText As String
Dim i As Long
vFindText = Array("^w^p", "OPT", "INP", "Remote", "Non VA")
vReplText = Array("^p", "|OPT|", "|INP|", "|Remote|", "|NonVA|")
For i = LBound(vFindText) To UBound(vFindText)
sFindText = vFindText(i)
sReplText = vReplText(i)
With ActiveDocument.Sections(3).Range.Find
.Forward = True
.Wrap = wdFindContinue
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Format = True
.MatchCase = False
.Text = sFindText
.Replacement.Text = sReplText
.Execute Replace:=wdReplaceAll
End With
Next i
End Sub
You don't know what you don't know...