Link to home
Start Free TrialLog in
Avatar of AndresHernando
AndresHernando

asked on

MS Word - Macro to delete last 3 pages of document

I have a 5-page MS Word document and want to put in a button or other mechanism that will allow the user to delete the last 3 pages of the document, which are instructions, leaving only the first two pages.

Thanks, --Andres
Avatar of AndresHernando
AndresHernando

ASKER

...note:  The document has "Editing Restrictions": Allow only this type of editing in the document: Filling in forms.   This means that the VBA code must temporarily removethe editing restriction.
Not sure how to handle the editing restrictions, but a sequence like this will delete all but the first three pages of a document.  Jump to page 4, back up a character, select through to end-of-document, and delete selection.

    Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="4"
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.EndKey Unit:=wdStory, Extend:=wdExtend
    Selection.Delete Unit:=wdCharacter, Count:=1

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial