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

Re: How to get the record macro to repeat through entire document, EOF, etc. by Cindy

Cindy
Wed Apr 18 11:27:31 CDT 2007

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 :-)