mantooth29
08-04-2012, 10:06 AM
Hello
I have the following code that loops through a mail merge output document, and copies a name in the greeting line. I have watched the behavior of the macro when it executes. It seems to go back and forth over the same section indefinitely, never actually making it to the next result and eventually crashing.
I recorded the macro to make sure the selection.find command was going to the next section, so I am guessing my problem lies in how I set up the loop.
Selection.Find.ClearFormatting
Selection.Find.Text = "and Team"
With Selection.Find
.Text = "and Team"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Do While Selection.Find.Found
Selection.MoveLeft Unit:=wdCharacter, Count:=2, Extend:=wdExtend
Selection.Copy
Selection.MoveDown Unit:=wdParagraph, Count:=1
Selection.Find.Execute
Loop
Any help is much appreciated!
I have the following code that loops through a mail merge output document, and copies a name in the greeting line. I have watched the behavior of the macro when it executes. It seems to go back and forth over the same section indefinitely, never actually making it to the next result and eventually crashing.
I recorded the macro to make sure the selection.find command was going to the next section, so I am guessing my problem lies in how I set up the loop.
Selection.Find.ClearFormatting
Selection.Find.Text = "and Team"
With Selection.Find
.Text = "and Team"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Do While Selection.Find.Found
Selection.MoveLeft Unit:=wdCharacter, Count:=2, Extend:=wdExtend
Selection.Copy
Selection.MoveDown Unit:=wdParagraph, Count:=1
Selection.Find.Execute
Loop
Any help is much appreciated!