View Single Post
 
Old 02-28-2024, 08:54 AM
RobiNew RobiNew is offline Windows 10 Office 2016
Competent Performer
 
Join Date: Sep 2023
Posts: 200
RobiNew is on a distinguished road
Default

I've taken up again the second macro at #6 above, but I get problems.
I have a docx of 7 pages. I need to go to page 4 and then delete pages 4 to 7. The macro works all right on its own, but it deletes all the pages of the docx when inserted into a larger (very large) macro. Can someone fancy why? Thanks!

Code:
Sub DeleteFromPgToEnd()
Dim oRng As Range
    Set oRng = ActiveDocument.Range
    Set oRng = oRng.GoTo(What:=wdGoToPage, Name:=4)
    Set oRng = oRng.GoTo(What:=wdGoToBookmark, Name:="\page")
    oRng.End = ActiveDocument.Range.End
    oRng.Delete 'doesn't delete the last empty page
  oRng.Collapse wdCollapseEnd
  oRng.Start = oRng.Start - 1
  oRng.Delete 'deletes the last empty page
End Sub
Reply With Quote