How to get the record macro to repeat through entire document, EOF, etc.

J

JB

Hi all:

I recorded the is macro to help me covert a file to a specific
format. The following works but I need it to repeat through the
entire file:

Selection.Find.ClearFormatting
With Selection.Find
.Text = "cn=""*"""
.Replacement.Text = "oldr"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.copy
Selection.EndKey Unit:=wdLine
Selection.Find.ClearFormatting
With Selection.Find
.Text = "newrdn:"
.Replacement.Text = "oldr"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.PasteAndFormat (wdPasteDefault)
Repeat
End Sub

Thanks for all your help in advance!

JB
 
C

Cindy M.

Hi Jb,

You should find an article on the word.mvps.org site that shows
how to "loop" using Find. To summarize: you put the code in a
Do...Loop and check whether Find.Execute was successful (that
returns a boolean). If it was not, then you exit the loop.
I recorded the is macro to help me covert a file to a specific
format. The following works but I need it to repeat through the
entire file:

Selection.Find.ClearFormatting
With Selection.Find
.Text = "cn=""*"""
.Replacement.Text = "oldr"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.copy
Selection.EndKey Unit:=wdLine
Selection.Find.ClearFormatting
With Selection.Find
.Text = "newrdn:"
.Replacement.Text = "oldr"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.PasteAndFormat (wdPasteDefault)
Repeat
End Sub

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17
2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 

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