deleting pages

N

Nathan Franklin

Hello list,

I am wanting to delete a certain number of pages in my document. I was
wandering what the best method would be to achieve this.

At the moment I have an empty bookmark, so I can get the Range of that item
and then call the .Information property on that object to get the current
page... How then can I delete all the previous pages before that. The
bookmark is on page 5 i need to delete page 1,2,3 & 4

Thanks guys

Nathan
 
G

Greg Maxey

Nathan,

AFAIK, you can't delete "pages" per say as a page doesn't really exists
until it is displayed (either on the screen or paper by a print driver).
You could possibly set a range the the start of the document up to and
including your empty bookmark and then delete that range.

Sub Test()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
oRng.End = ActiveDocument.Bookmarks("Test").Range.End
oRng.Delete
End Sub
 
N

Nathan Franklin

Greg,

thanks for your reply

I have successfully deleted the range. I am struggling now with delete the
other half. There are case where I need to leave the start of the doc and
delete the end of the doc.

I use this code to delete the end of the doc

Dim delRange As Word.Range

delRange = Doc.Bookmarks.Item("PestReportStartingPage").Range

delRange.End = Doc.Range.End

delRange.Select()

App.Selection.Delete()



This deletes all the content but leaves the last page in the document along
with the bookmark. even if i delete the bookmark after deling the end range
the last page still satys there... is there anyway I can get rid of the last
page??



Thanks mate



nathan
 
J

Jezebel

The problem with your code is this line --

delRange = Doc.Bookmarks.Item("PestReportStartingPage").Range

A range is an object, so you have to use 'Set' when you assign a variable:

Set delRange = Doc.Bookmarks.Item("PestReportStartingPage").Range

You don't need to select a range to delete it. (The Selection is, in any
case, just a special case of range.) You can delete the range itself:

delRange.Delete


Simpler still --

With ActiveDocument
.Range(.Bookmarks("PestReportStartingPage").Range.Start,
..Range.End).Delete
End with
 
G

Greg Maxey

How about:

Sub Test()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
oRng.Start = ActiveDocument.Bookmarks("Test").Range.Start
oRng.Delete
End Sub
 
N

Nathan Franklin

Greg,

Unfortunatley still not working...

I think i have ehusted all methods. Its just the last page I cant get rid
of.

this is my latest attempt (vb.net)
Doc.Bookmarks.Item("PestReportStartingPage").Select()

delRange = Doc.Range

delRange.Start = Doc.Bookmarks.Item("\page").Range.Start

delRange.End = Doc.Range.End

delRange.Delete()

Doc.Bookmarks.Item("PestReportStartingPage").Select()

Doc.Bookmarks.Item("\page").Range.delete


This leaves the bookmark "PestReportStartingPage" on an empty page.

Is there any other way of getting rid of that last page??

Thanks heaps

Nathan
 

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