none
Deleting Pages in Word with Section Breaks RRS feed

  • Question

  • Hi, I'm creating a work instruction template to be used company wide. This WI has 4 pages:

    1. A3 landscape

    2. A4 landscape

    3. A4 portrait

    4. A3 portrait

    I want the user to be able to choose what size they want to use and just delete the unwanted pages. I saw this macro in one of the forums but it still doesn't recognize the last page for some reason:

    Sub DeleteActivePage()

    Dim Message, Title, Default, Request
    Dim rgePages As Range
    Dim finalPage
    Dim iPage As Long
    'Input Page Request
    Message = "Enter the page number to delete"
    Title = "Page Removal"
    Default = Selection.Information(wdActiveEndPageNumber)
    On Error Resume Next
    iPage = InputBox(Message, Title, Default)
    With ActiveDocument
        Set rgePages = .GoTo(What:=wdGoToPage, Name:=iPage)
        Set rgePages = rgePages.GoTo(What:=wdGoToBookmark, Name:="\page")
        rgePages.Delete
    End With
    'Find Last page and remove it if selected for removal
    finalPage = ActiveDocument.Range.Information(wdActiveEndAdjustedPageNumber)
    If finalPage = CInt(iPage) Then
    ActiveDocument.Bookmarks("\Page").Range.Delete
    Selection.MoveLeft Extend:=wdExtend
    Selection.Delete
    End If
    End Sub

    Can you please help?

    Thursday, October 11, 2018 3:17 AM

Answers

All replies