Most of the code inside your loop can be outside it - the settings only need
doing once, so you could have
.Forward = True
.Wrap = wdFindContinue
.MatchWholeWord = True
MatchAllWordForms = False
Do While XAB < 40
.Execute FindText:="%<>%"
Selection.Rows.Delete
XAB = XAB + 1
Loop
That makes it easier to see what's going on. Now, what you want is to check
if the execute has been successful. As it returns a True/False value, you
can do this
Do While XAB < 40
If .Execute FindText:="%<>%" Then
Selection.Rows.Delete
Else
Exit Do
End If
XAB = XAB + 1
Loop
Now you can see that the XAB variable is unnecessary ...
Do
If .Execute FindText:="%<>%" Then
Selection.Rows.Delete
Else
Exit Do
End If
Loop
which can be shortened to:
Do While .Execute FindText:="%<>%"
Selection.Rows.Delete
Loop
Giving complete code of:
.Forward = True
.Wrap = wdFindContinue
.MatchWholeWord = True
MatchAllWordForms = False
Do While .Execute FindText:="%<>%"
Selection.Rows.Delete
Loop
Enjoy,
Tony
> The thing is I would actually like to find a conditional statement that would
> tell the loop to exit when there were no more of the strings that it is
[quoted text clipped - 36 lines]
> > >
> > > Any suggestions would be appreciated.
Beamer - 29 Sep 2005 20:56 GMT
The first tip that you gave will reduce the lines run, however I ran into a
problem where the If statement ( If .Execute FindText:="%<>%" Then) throws an
error because of an error in the conditional statement. I believe that the
error directly relates to the space between .Execute and FindText. Is there
a way to correct this error using brackets, or do I need to use an entirely
different conditional statement?
-Beamer
> Most of the code inside your loop can be outside it - the settings only need
> doing once, so you could have
[quoted text clipped - 97 lines]
> > > >
> > > > Any suggestions would be appreciated.
Tony Jollans - 29 Sep 2005 21:36 GMT
My apologies - I should test instead of just typing :)
The correct syntax is:
If .Execute(FindText:="%<>%") Then
and, in the While:
Do While .Execute(FindText:="%<>%")
Enjoy,
Tony
> The first tip that you gave will reduce the lines run, however I ran into a
> problem where the If statement ( If .Execute FindText:="%<>%" Then) throws an
[quoted text clipped - 106 lines]
> > > > >
> > > > > Any suggestions would be appreciated.