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

G

geodoig

* 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?
 
T

Tony Jollans

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
 

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