combining two loops into one

J

John Smith

Can the following two loops be combined into one? I need to do
multiple find and replace and it's taking a long time. I hope if I
can do multiple find and replace in just one loop, it'll take less
time.

Do While .Execute(FindText:=" <", ReplaceWIth:="<",
MatchWildcards:=False, Wrap:=wdFindContinue, Forward:=True) = True
Loop

Do While .Execute(FindText:="(", ReplaceWIth:=vbTab + "(",
MatchWildcards:=False, Wrap:=wdFindContinue, Forward:=True) = True
Loop
 
J

Jay Freedman

Can the following two loops be combined into one? I need to do
multiple find and replace and it's taking a long time. I hope if I
can do multiple find and replace in just one loop, it'll take less
time.

Do While .Execute(FindText:=" <", ReplaceWIth:="<",
MatchWildcards:=False, Wrap:=wdFindContinue, Forward:=True) = True
Loop

Do While .Execute(FindText:="(", ReplaceWIth:=vbTab + "(",
MatchWildcards:=False, Wrap:=wdFindContinue, Forward:=True) = True
Loop

They can't be combined, but there's no reason to do loops, which are
just time-wasters.

Include the parameter Replace:=wdReplaceAll in each .Execute and call
it just once:

.Execute FindText:=" <", ReplaceWIth:="<", _
MatchWildcards:=False, Wrap:=wdFindContinue, _
Forward:=True, Replace:=wdReplaceAll
.Execute FindText:="(", ReplaceWIth:=vbTab + "(", _
MatchWildcards:=False, Wrap:=wdFindContinue, _
Forward:=True, Replace:=wdReplaceAll
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top