N
Neal
Hi -
I was trying to incorporate in my code the Sub DoFindReplace(FindText As String, ReplaceText As String)
in Dave Rado's article "How to cut out repetition..." http://word.mvps.org/FAQs/MacrosVBA/ProcArguments.htm
but I seem to be caught in the loop.
My find and replace operations are:
Call DoFindReplace("^p", "@@^p")
Call DoFindReplace"@@^p@@^p", "^p")
Call DoFindReplace"@@^p", "^t")
Since the ^p isn't removed, it stays in the loop and just keeps adding more and more @@.
Question: How can I adapt the loop statement so that it only replaces ^p to @@^p one time for
each occurrence?
Here's the code:
Sub DoFindReplace(FindText As String, ReplaceText As String)
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = FindText
.Replacement.Text = ReplaceText
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
Do While .Execute
'Keep going until nothing found
.Execute Replace:=wdReplaceAll
Loop
'Free up some memory
ActiveDocument.UndoClear
End With
End Sub
Thanks in advance for your help.
Neal
I was trying to incorporate in my code the Sub DoFindReplace(FindText As String, ReplaceText As String)
in Dave Rado's article "How to cut out repetition..." http://word.mvps.org/FAQs/MacrosVBA/ProcArguments.htm
but I seem to be caught in the loop.
My find and replace operations are:
Call DoFindReplace("^p", "@@^p")
Call DoFindReplace"@@^p@@^p", "^p")
Call DoFindReplace"@@^p", "^t")
Since the ^p isn't removed, it stays in the loop and just keeps adding more and more @@.
Question: How can I adapt the loop statement so that it only replaces ^p to @@^p one time for
each occurrence?
Here's the code:
Sub DoFindReplace(FindText As String, ReplaceText As String)
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = FindText
.Replacement.Text = ReplaceText
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
Do While .Execute
'Keep going until nothing found
.Execute Replace:=wdReplaceAll
Loop
'Free up some memory
ActiveDocument.UndoClear
End With
End Sub
Thanks in advance for your help.
Neal