View Single Post
 
Old 02-28-2024, 12:04 PM
vivka vivka is offline Windows 7 64bit Office 2016
Expert
 
Join Date: Jul 2023
Posts: 302
vivka is on a distinguished road
Default

Hi, RobiNew! Welcome back!
Try your slightly changed code:
Code:
Sub DeleteFromPgToEnd()Sub Del_From_Pg_To_End()
'Delete pages from PgNum till the doc's end.

Dim rng As range
Dim PgNum As String
    PgNum = InputBox("Enter the number of the page")
    Set rng = ActiveDocument.range.GoTo(wdGoToPage, PgNum)
    rng.End = ActiveDocument.range.End
'If there's a page break before the PgNum page, the pages won't get
'deleted, so move the rng's start:
    If rng.Characters.First.Previous = Chr(12) Then
        rng.Start = rng.Start - 1
    End If
    rng.Delete
End Sub

Last edited by vivka; 02-28-2024 at 12:30 PM. Reason: Useful addition
Reply With Quote