Bullfrog1870
Technical User
I'm trying to loop through a Word document and find all occurrences of a particular word. However, once it finds all of them, the Do-Until loop appears to lock up or get stuck since it really hasn't hit the end of document. If I change the .Wrap property to wdFindContinue it just loops indefinitely. Either way, I have to kill (Ctl-Alt-Del) Word.
How do I exit my loop once I've found the last occurrence in the document?
Note: I've not put in my actions once I find "NewYork". I haven't gotten that far.
Thank you!
Sub Macro1()
Do Until ActiveDocument.Bookmarks("\Doc") = ActiveDocument.Bookmarks("\EndOfDoc")
Selection.Find.ClearFormatting
With Selection.Find
.Text = "NewYork"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.CorrectHangulEndings = True
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
End With
Selection.Find.Execute
Loop
End Sub
How do I exit my loop once I've found the last occurrence in the document?
Note: I've not put in my actions once I find "NewYork". I haven't gotten that far.
Thank you!
Sub Macro1()
Do Until ActiveDocument.Bookmarks("\Doc") = ActiveDocument.Bookmarks("\EndOfDoc")
Selection.Find.ClearFormatting
With Selection.Find
.Text = "NewYork"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.CorrectHangulEndings = True
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
End With
Selection.Find.Execute
Loop
End Sub