Delete page

J

Jean-Guy Marcil

Fuzzhead was telling us:
Fuzzhead nous racontait que :
Is there a way to create a macro to delete only the page that my
curser is in?

Selection.Bookmarks("\Page").Range.Delete

But beware of section breaks that may be deleted...

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
F

Fuzzhead

This works good until I get to the last page. When I run it on the last page
it does not delete it. It only deletes the text in the page.
 
J

Jean-Guy Marcil

Fuzzhead was telling us:
Fuzzhead nous racontait que :
This works good until I get to the last page. When I run it on the
last page it does not delete it. It only deletes the text in the page.

This happens when it happens that the last ¶ of the document (which the code
does not delete) does not fit at the end of the page before lat (which
should be the last page when the code executes).

You will have to add code to detect if you are on the last page, if so,
handle that one separately. For example:

'_______________________________________
If Selection.Information(wdActiveEndAdjustedPageNumber) = _
ActiveDocument.ComputeStatistics(wdStatisticPages) Then
Selection.Bookmarks("\Page").Range.Delete
Selection.TypeBackspace
Else
Selection.Bookmarks("\Page").Range.Delete
End If
'_______________________________________

It will probably need modification according to the type of document you are
handling and the type of content.



--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
F

Fuzzhead

This is part of my template for creating a new procedure. The last page is
for attachments in landscape if needed. It has a header and footer. If the
procedure does not require any attachments in landscape I want to delete it.
Would I have to delete the header/footer first and then delete the page?
 
J

Jean-Guy Marcil

Fuzzhead was telling us:
Fuzzhead nous racontait que :
This is part of my template for creating a new procedure. The last
page is for attachments in landscape if needed. It has a header and
footer. If the procedure does not require any attachments in
landscape I want to delete it. Would I have to delete the
header/footer first and then delete the page?

This means that there is a section break at the end of the preceding page,
right?

In such cases, if you simply delete the last section break, it may happen
that your Landscape header/footer that were the document last section's
header/footer will become the document last header/footer after you delete
this section break.

To make sure you have no problem, first set the landscape section
header/footer to "Same as Previous" (Make sure you cycle through all type of
header/footer if necessary: First, Even, Primary). Then delete the section
break and any superfluous paragraph marks (¶).

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.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