PDA

View Full Version : [SOLVED:] Macro not quite working right



mikewi
11-16-2016, 06:05 AM
I have a macro that looks for 3 returns and replaces with 2. I have the wrap set to "wdFindContinue" but it's not finding all of them. It stops after the first one?? I can't see what I'm doing wrong. Any suggestions?


Sub Replace2returnsWith1()
'
' Replace2returnsWith1 Macro
'
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p^p^p"
.Replacement.Text = "^p^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Paul_Hossler
11-16-2016, 06:53 AM
If there are more that 3 in a row, the replace has already moved past, and misses one

Try this (with .Wildcards = True)

Look at the attachment with the para markers color coded to see the original macro's results




Sub AltMacro()

With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "^13{3,}"
.Replacement.Text = "^p^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
End Sub

mikewi
11-16-2016, 07:58 AM
Paul thank you so much really appreciate your help.