View Single Post
 
Old 11-17-2023, 07:41 AM
RobiNew RobiNew is offline Windows 10 Office 2016
Competent Performer
 
Join Date: Sep 2023
Posts: 200
RobiNew is on a distinguished road
Default

Hi, everybody! I have devised a different approach. But how do you get rid of the last page? Thanks!
Code:
Sub DeleteFromNrToEnd()
Dim rng As Range
ActiveDocument.PageSetup.TextColumns.SetCount NumColumns:=1
    Set rng = ActiveDocument.Range(0, 0)
    Set rng = rng.GoTo(What:=wdGoToPage, Name:=4)
    Set rng = rng.GoTo(What:=wdGoToBookmark, Name:="\page")
    rng.End = ActiveDocument.Range.End
    rng.Delete
End Sub

Can this one be improved?
Code:
Sub DeleteFromNrToEnd()
Dim rng As Range
ActiveDocument.PageSetup.TextColumns.SetCount NumColumns:=1
    Set rng = ActiveDocument.Range(0, 0)
    Set rng = rng.GoTo(What:=wdGoToPage, Name:=4)
    Set rng = rng.GoTo(What:=wdGoToBookmark, Name:="\page")
    rng.End = ActiveDocument.Range.End
    rng.Delete
With ActiveDocument
    LastChr = .GoTo(wdGoToPage, wdGoToLast).Start
    .Range(LastChr - 1, ActiveDocument.Range.End).Delete
End With
End Sub
Reply With Quote