0
votes

In MS Word using a macro, I would like to find the last line of the current page and add a "page break". Although this should be easy I can't find the script for the last line of the current page.

Sub LastLineInsert()
    Selection-end       'is supposed to work to find last line
    Selection.InsertBreak Type:=wdPageBreak
EndSub
1

1 Answers

3
votes

The easiest way is probably to use Selection.GoToNext(wdGoToPage) and then back up one character. So:

Selection.GoToNext(wdGoToPage)
Selection.MoveEnd wdCharacter, -1
Selection.InsertBreak

Note that doing this where Word has already made a page break can result in a blank page being added. Be careful about this if you're trying to loop.