indi visual
Member
Looking for help with a loop that stops after searching entire document and finding zero matches.
I am using MS Word.
Other codes I have tried so far were either very slow, or they froze up on me.
The code I pasted below is much quicker and works fine;
However,
I will not always know how many times I need to loop, therefore I was hoping someone could please provide feedback on a loop that finishes once no more instances are found.
[pre]<br />
Sub SPECIFIED_LOOP()<br />
Application.ScreenUpdating = False<br />
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''<br />
Dim i As Integer<br />
i = 1<br />
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''<br />
Do Until i = 436 'I WAS HOPING I WOULDN'T HAVE TO SPECITY A NUMBER HERE<br />
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''</p>
<p>'my code is here, and I don't know if it's necessary for getting help so I will paste it below</p>
<p>'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''<br />
i = i + 1<br />
Loop<br />
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''<br />
Application.ScreenUpdating = True<br />
End Sub<br />
Here is the inserted code I was using in case this is necessary:
<br />
Selection.Find.ClearFormatting<br />
With Selection.Find<br />
.Text = "OPENBRACKET*.txt"<br />
.Replacement.Text = "ENDBRACKET"<br />
.Forward = True<br />
.Wrap = wdFindContinue<br />
.Format = False<br />
.MatchCase = False<br />
.MatchWholeWord = False<br />
.MatchAllWordForms = False<br />
.MatchSoundsLike = False<br />
.MatchWildcards = True<br />
End With<br />
Selection.Find.Execute<br />
Selection.EndKey Unit:=wdLine<br />
Selection.MoveLeft Unit:=wdCharacter, Count:=4<br />
Selection.TypeText Text:=""<br />
[/pre]
I am using MS Word.
Other codes I have tried so far were either very slow, or they froze up on me.
The code I pasted below is much quicker and works fine;
However,
I will not always know how many times I need to loop, therefore I was hoping someone could please provide feedback on a loop that finishes once no more instances are found.
[pre]<br />
Sub SPECIFIED_LOOP()<br />
Application.ScreenUpdating = False<br />
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''<br />
Dim i As Integer<br />
i = 1<br />
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''<br />
Do Until i = 436 'I WAS HOPING I WOULDN'T HAVE TO SPECITY A NUMBER HERE<br />
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''</p>
<p>'my code is here, and I don't know if it's necessary for getting help so I will paste it below</p>
<p>'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''<br />
i = i + 1<br />
Loop<br />
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''<br />
Application.ScreenUpdating = True<br />
End Sub<br />
Here is the inserted code I was using in case this is necessary:
<br />
Selection.Find.ClearFormatting<br />
With Selection.Find<br />
.Text = "OPENBRACKET*.txt"<br />
.Replacement.Text = "ENDBRACKET"<br />
.Forward = True<br />
.Wrap = wdFindContinue<br />
.Format = False<br />
.MatchCase = False<br />
.MatchWholeWord = False<br />
.MatchAllWordForms = False<br />
.MatchSoundsLike = False<br />
.MatchWildcards = True<br />
End With<br />
Selection.Find.Execute<br />
Selection.EndKey Unit:=wdLine<br />
Selection.MoveLeft Unit:=wdCharacter, Count:=4<br />
Selection.TypeText Text:=""<br />
[/pre]