delete page

P

Patrick

I have a long document divided into separate pages using page breaks


I want to delete every page which does not contain a particular keyword

How do I
1. Search just each page one by one
2. Delete any complete page if a keyword is not found

Thanks
 
H

Helmut Weber

Hi Patrick,
like this and in some other ways,
just to show a possible approach in principle:

Dim l As Long
Dim lPgs As Long ' number of pages
lPgs = ActiveDocument.BuiltInDocumentProperties("number of pages")
With Selection
For l = lPgs To 1 Step -1
.GoTo what:=wdGoToPage, Count:=l
.Bookmarks("\page").Select
If InStr(.Text, "keyword") = 0 Then
.Range.Delete
End If
Next
End With

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

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