I'm trying to use the Find & Replace feature in Word within a Do Loop statement to sequentially replace the same text string with different variables. My question is how to structure the Do statement to stop when it no longer finds the text string to be replaced. The code I'm using is:
I can't just use wdReplaceAll, because each instance of the text I'm looking for will be replaced with a different variable (for instance, it should replace the letter "a" with a different variable each time it finds it.)
I've figured out how to count the number of occurrences of the text I'm looking for, then execute the Do statement that number of times, but I'm thinking there's got to be a more efficient way to do it.
Thanks!
Code:
Do Until ???????
Selection.HomeKey Unit:=wdStory
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute “variable”, True, False, False, False, False, True, , , “replacement variable”, wdReplaceOne
End With
Loop
I can't just use wdReplaceAll, because each instance of the text I'm looking for will be replaced with a different variable (for instance, it should replace the letter "a" with a different variable each time it finds it.)
I've figured out how to count the number of occurrences of the text I'm looking for, then execute the Do statement that number of times, but I'm thinking there's got to be a more efficient way to do it.
Thanks!