Delete page (that includes a header & footer)

B

Barry555

I'm trying to delete the last page of a 4 page document. All pages have the
same header and footer.

I've tried macropod's code from 15/8/08 (slightly amended as I'm using late
binding):

objDoc.Application.Selection.Goto 1, -1 ' wdGoToPage, wdGoToLast
objDoc.Bookmarks("\Page").Range.Delete

This clears all the text (except in the header & footer) from the page, but
doesn't actually delete the page! I'm assuming this is because of the header
and footer. How can I actually delete the page?
 
J

Jonathan West

Barry555 said:
I'm trying to delete the last page of a 4 page document. All pages have
the
same header and footer.

I've tried macropod's code from 15/8/08 (slightly amended as I'm using
late
binding):

objDoc.Application.Selection.Goto 1, -1 ' wdGoToPage, wdGoToLast
objDoc.Bookmarks("\Page").Range.Delete

This clears all the text (except in the header & footer) from the page,
but
doesn't actually delete the page! I'm assuming this is because of the
header
and footer. How can I actually delete the page?

I suspect that there is a single blank paragraph at the end of the document
which is just about wrapping onto the final page. Try deleting the
last-but-one character in the document.
 
L

Lene Fredborg

The same would happen even if the header and footer were empty. If you turn
on formatting marks, you will see that an empty paragraph is left on the last
page after running the macro. Try to add the following line of code to you
macro:

objDoc.Paragraphs.Last.Range.Delete

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
B

Barry555

Yes!!!

Thank you Lene, that did it.

Barry.

Lene Fredborg said:
The same would happen even if the header and footer were empty. If you turn
on formatting marks, you will see that an empty paragraph is left on the last
page after running the macro. Try to add the following line of code to you
macro:

objDoc.Paragraphs.Last.Range.Delete

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 

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