R – No Dangling Word Headings Between Page Breaks

ms-wordvba

Does anyone have a good VBA way (or perhaps there is an MS Word setting I can't find) to make sure that Word headings do not dangle at the end of a page.

For example, assume that the numbers on the left are page numbers.

1  This is the second to last line on the page.
1  HEADING 1
2  This text starts page two

What I want to do is automatically move Heading 1 down so that:

1  This is the second to last line on the page.
1  
2  HEADING 1
2  This text starts page two

I am familiar with this question:
Getting the headings from a Word document

Thanks!

Best Solution

You want "keep with next" (Paragraph formatting > Line and Page breaks tab).

Possibly also of interest: Widow/Orphan control

Related Question