Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove page and make document even # of pages? 2

Status
Not open for further replies.

cheriberi

Technical User
May 27, 2003
60
US
Is it possible via VBA in Word to remove the last page of a document (starting with the last page break), then make sure that the document has an even number of pages (if odd number, add a page break at the end)?
 
Hi Cheryl,

I think this will do it for you:

Code:
With Selection

    .EndKey Unit:=wdStory

    .Find.ClearFormatting
    .Find.Execute FindText:="^m", Forward:=False, Wrap:=wdFindStop

    If .Find.Found Then
        .MoveEnd wdStory
        .Delete
    End If

End With

If ActiveDocument.BuiltInDocumentProperties(wdPropertyPages) Mod 2 = 1 Then
    Selection.EndKey Unit:=wdStory
    Selection.InsertBreak Type:=wdPageBreak
End If

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top