Here's one way:
Sub DeletePages()
Dim i As Integer
Dim MyRange As Range
Set MyRange = ActiveDocument.Range(0, 0)
For i = ActiveDocument.Range.Information(wdActiveEndPageNumber) To 1 Step -1
If i = 7 Or i = 7 Or i = 9 Or i = 10 Or i = 12 Then
Set MyRange = MyRange.GoTo(What:=wdGoToPage, Name:=i)
Set MyRange = MyRange.GoTo(What:=wdGoToBookmark, Name:="\page")
MyRange.Delete
End If
Next
End Sub
--
Cheers
macropod
[MVP - Microsoft Word]
"Flash Gordon" <Flash Gor...@discussions.microsoft.com> wrote in message news:B56BF3D2-3644-4C05...@microsoft.com...
However, here are some tips that may assist you in your efforts:
Consider deleting the last page first. The reason for this should be fairly
obvious: as soon as you delete, for example, page 7, page 9 is now page 8,
page 10 is page 9, and so on. Deleting the last page first avoids this
problem.
You may be tempted to select the page you want to delete and then delete the
selection. With only four pages to delete, this would probably be acceptable.
However, it's better practice to define a Range object for the page and then
delete the specified range. This will be quicker and won't cause the screen
to jump around.
In addition, due to the fact that the Page object has no Delete method and
no Range property , you will not be able to work with the Page object
directly. Instead, you will have to use the range of the hidden "\page"
bookmark for each page, as shown in the sample code that macropod has
provided (which actually shows practical application of all the
recommendation outlined above).
Finally, if at all possible, I would look for a way to explicitly define the
content to be deleted - possibly though the use of a series of bookmarks.
This will help to avoid the problems associated with the imprecision inherent
in Word's definition of a page.
BTW, I would be tempted to use a 'Select Case' statement in place of
macropod's 'If' statement, as follows:
<snip>
Select Case i
Case 7, 9, 10, 12
Set MyRange = MyRange.GoTo(What:=wdGoToPage, Name:=i)
Set MyRange = MyRange.GoTo(What:=wdGoToBookmark, Name:="\page")
MyRange.Delete
Case Else
' Do nothing
End Select
<snip>
However, this is just a matter of personal preference in that I find this
construction to be a bit more "descriptive" and simpler to understand, debug
and maintain. A series of 'Or' comparisons, while perfectly acceptable to the
machine, can be a bit more difficult for "wetware" to interpret. (And 'Case'
statements just look prettier IMHO... <g>)
--
Cheers!
Gordon
Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
Making a copy of a document and deleting the unwanted pages from it to make a sub-set, is probably as easy as, if not easier than,
copying the 'wanted' pages to a new file. Apart from not making the copy for you - which you didn't ask for - the code I posted
takes the first course.
--
Cheers
macropod
[MVP - Microsoft Word]
"Flash" <Fl...@discussions.microsoft.com> wrote in message news:E3568DE7-B19F-4E6C...@microsoft.com...