An implementation of Visual Basic that is built into Microsoft products.
The macro is restarting at the beginning because .Wrap = wdFindContinue tells Word to keep searching from the start after reaching the end. To move only to the next match from the current position, use wdFindStop and execute the find in a loop so it continues from the current selection.
Example adjusted macro:
Sub Horse_Above_10()
With Selection.Find
.ClearFormatting
.Font.Size = 12
.Text = "\) [0-9]{2,} [A-Z]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop 'Stop at end; do not continue from top
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
'Find next occurrence from current cursor position
If Selection.Find.Execute Then
'Now Selection is on the found text
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
End If
End Sub
Key changes:
-
.Wrap = wdFindStopso the search does not wrap to the beginning. -
Selection.Find.Executeis used once per run to move to the next match from the current cursor position.
If multiple occurrences must be processed in one run, wrap the Execute and subsequent actions in a Do While Selection.Find.Execute loop, similar to the loop pattern shown in the sample macro in the references.
References: