Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2004

Tip: Looking for answers? Try searching our database.

Deleting Page Breaks

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Thomas M - 09 Nov 2004 10:23 GMT
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
Jay Freedman - 09 Nov 2004 15:19 GMT
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.

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Word 2000
>
[quoted text clipped - 21 lines]
>
> --Tom
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.