Deleting Page Breaks

T

Thomas M

Word 2000

What is the easiest way to delete all the page breaks in a document? I
recorded the following:

Selection.HomeKey Unit:=wdStory
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^m"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll

This seems to work well, but if the document was large it could take a
while to search through the entire document.

I'm wondering if there is another way to do this, maybe by using a
collection or something, where the code would loop through all the page
breaks in the document and delete them. I thought that I was on to
something when I was reading about the Sections collection, but that does
not appear to apply to page breaks.

--Tom
 
J

Jay Freedman

Hi Thomas,

The Find/Replace All is definitely the fastest method of deleting manual
page breaks, much faster than iterating through any collection. However, you
can improve on the recorded code by replacing the Selection object with a
Range object, like this:

Dim myRange As Range
Set myRange = ActiveDocument.Range
With myRange.Find
.Text = "^m"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With

The advantage of the Range object is that it doesn't move the cursor (which
is represented by the Selection object), so Word doesn't have to scroll or
redraw the screen. This can easily speed up the macro by a factor of 5 or
more in a long document.
 

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