Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm clearly a newbie, and this may be the wrong site to ask a question, but I'm desperate:

I've got a Find and replace operation that deletes four instances of a certain string, then leaves one instance intact.

What I'd like to do is have this whole operation loop until the end of the file.

Every loop I come up with turns infinite. Sample code online doesn't seem to work for me. This, for example:
VB
Do Until ActiveDocument.Bookmarks("\Sel") = _
   ActiveDocument.Bookmarks("\EndOfDoc")
Posted

1 solution

Well, you can do it in this pattern. You can add a counter and check it for every fifth occurence.

Dim myStoryRange As Microsoft.Office.Interop.Word.Range
For Each myStoryRange In doc.StoryRanges
 With myStoryRange.Find
 .Text = "targetstring"
 .Replacement.Text = ""
 .Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindAsk
 .Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceOne)
End With
Next myStoryRange
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900