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 / August 2006

Tip: Looking for answers? Try searching our database.

how do i delete a page in Word (based on contents) via a macro?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
geodoig - 23 Aug 2006 20:44 GMT
* i am currently using MS Word 2000

* i regularly deal with long documents (250+ pages) to which i apply a
highlight macro

* each page is separated with a page break

* rather than having to pore over the entire document, i would like to
delete (clear text from?) all pages with no highlights

* any ideas on how to implement this action with a macro?
Tony Jollans - 24 Aug 2006 13:36 GMT
The manual page breaks make it quite easy to use Find and Replace for what
might otherwise be more complex.

1. Add an extra page break at front and rear so that all (original) pages
are bound by two page breaks
2. Replace All PageBreak-TextWithoutHighLight-PageBreak by PageBreak
3. Remove the extra page breaks added in step 1.

Step 2 actually needs to repeated (as often as necessary) because it doesn't
automatically delete consecutive pages without highlighting.

Here's some code:

   With ActiveDocument
       .Range(.Range.Start, .Range.Start).InsertBreak wdPageBreak
       .Range(.Range.End - 1, .Range.End - 1).InsertBreak wdPageBreak

       With .Range.Find
           .ClearFormatting
           .Replacement.ClearFormatting
           .Highlight = False
           .MatchWildcards = True
           .Text = "^m*^m"
           .Replacement.Text = "^m"
           .Wrap = wdFindContinue
           .Format = True
           While .Execute
               .Execute Replace:=wdReplaceAll
           Wend
       End With

       .Range(.Range.Start, .Range.Start).Delete
       .Range(.Range.End - 2, .Range.End - 1).Delete
   End With

--
Enjoy,
Tony

> * i am currently using MS Word 2000
>
[quoted text clipped - 7 lines]
>
> * any ideas on how to implement this action with a macro?
 
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.