Getting the Range of the top of the next page in Word VBA

I needed a function that would conveniently return me a Range that contained the top of the next page in a Word document.

The following does the trick:

Function TopOfNextPage(rng As Word.Range) As Word.Range
    Set TopOfNextPage = rng.Duplicate.GoTo(What:=wdGoToPage, Which:=wdGoToNext)
End Function 

Notice it does not disturb the original Range. It accomplishes this by use of the Range.Duplicate function, which I find very handy sometimes when I don’t want to disturb my original Range.

Notice the returned Range is collapsed to the top of the page.

Leave a Reply

Your email address will not be published. Required fields are marked *