VBA Replace only within a RANGE in Word
Hi all,
I have a replace sub working, but need it to disregard the first page of this word document. The document could be any length, but just the first page needs to be ignored.
VB Code:
Selection.MoveDown Unit:=wdScreen, Count:=3
Selection.EndKey Unit:=wdStory, Extend:=wdExtend
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ".00"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.HomeKey Unit:=wdLine
Selection.HomeKey Unit:=wdStory
This selects everything from page 2 down, replaces the ".00" with nothing, and then takes the cursor home. BUT - when you run this macro (from on the toolbar), it does indeed replace these instances of ".00" from the first page.
Any help or suggestions???
Re: VBA Replace only within a RANGE in Word
[QUOTE=Scott_MacKenzie;1653059]Small alteration, and it works perfectly. the 'Wrap:=wdfindStop' makes the replace function only within the selection, and not continuing on through the rest of the document once finished with that selection.
With Selection.Find
.Execute Forward:=True, _
Wrap:=wdFindStop
End With
Thanks for this veritable PEARL OF WISDOM, SCOTT!