Word 2007 - Macro gets stuck searching for and replacing "^p^p"

C

Chris

I've created several Macros in 2003 that use a search function to replace
double Paragraph marks with a single paragraph mark. However, in 2007 the
function gets stuck and I have to press the ESC key to halt the process.

Even when I do this process manually within the document it gets "stuck" and
I have to press the ESC key to stop it.

NOTE: The document I'm running this against is a TXT file not a Word Document.

Any ideas????
 
J

Jonathan West

Chris said:
I've created several Macros in 2003 that use a search function to replace
double Paragraph marks with a single paragraph mark. However, in 2007 the
function gets stuck and I have to press the ESC key to halt the process.

Even when I do this process manually within the document it gets "stuck"
and
I have to press the ESC key to stop it.

NOTE: The document I'm running this against is a TXT file not a Word
Document.

Any ideas????

After each replace, get the value of ActiveDocument.Range.End

If it hasn't changed since last time, exit the loop.
 
C

Chris

Hmmm... where would this work. Here is my code.

Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p^p"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll
 
J

Jonathan West

Chris said:
Hmmm... where would this work. Here is my code.

Changed as follows

Dim i as Long

Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p^p"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
Do
i = ActiveDocument.Range.End
.Execute Replace:=wdReplaceAll
Loop Until i = ActiveDocument.Range.End
End With
 

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