View Single Post
 
Old 08-03-2018, 08:44 AM
Aliqux Aliqux is offline Windows 10 Office 2016
Novice
 
Join Date: Aug 2018
Posts: 1
Aliqux is on a distinguished road
Default

I found this post and it was very useful for what I was ding. I found an issue with deleting the last page of a document and also found a solution to it and thought I would share it as well.

Code:
 
Sub DeletePage()
'
' DeletePage Macro
' Requests the page number to delete and removes it
' 
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
Reply With Quote