Repeating a Macro

D

dz

This should do the trick:

If you are performing a search for the text object, then
use this code:

Search for text object

While Selection.Find.Found
your code here
Search for text object
Loop
 
I

ItZaBo

Tried it. I'm not sure of the format. I keep getting a loop witthout do error
here is the original macro. Might I be able to get you to insert it
correctly. I can take it from there once I see the correct format.

Selection.Find.ClearFormatting
With Selection.Find
.Text = "NORTH"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With

Selection.Find.Execute
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1

End Sub
THANKS!!!!!!!

Robert
 
D

DZ

It's the .wrap part - you need to set it to wdStop.

Anyway, here's what I suggest:

Sub Process()

FindIt "NORTH" 'is this supposed to be all caps?

While Selection.Find.Found
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
FindIt "NORTH"
Loop

End Sub

Sub FindIt(strSearch as String)

Selection.Find.ClearFormatting
With Selection.Find
.Text = strSearch
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False 'If supposed to be all caps,
change .MatchCase to True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute

End Sub
 
I

ItZaBo

GOT IT!!!!!!

I had to add a do before the while call.
Is this because i have office 97.
Either way. THANKS A MILLION!!!!!!!!!

Robert
 
J

Jonathan West

ItZaBo said:
GOT IT!!!!!!

I had to add a do before the while call.
Is this because i have office 97.

No, it is because the While loop should have ended with Wend instead of Loop
in the code DZ supplied. But Do While-Loop does exactly the same as
While-Wend in this context, so the code you nnow have should be fine.
 

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