Question

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!

Was it helpful?

Solution

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

Possibly also of interest: Widow/Orphan control

OTHER TIPS

It appears that the dangling header scenario you describe only occurs when the font is set manually and the Style is initially left at Normal.

If you set the Style on the headings to be Heading 1, 2, or 3, it will prevent the header from being left at the bottom of the page by itself.

If you decide to change your document to use Style-based headers, you will want to alter the Heading styles in the Styles and Formatting window.
To open that window, either:

  • Click the Styles and Formatting button on the toolbar (the "A" button to the left of the Font selector), or
  • Open it via the Format > Styles and Formatting... menu option.

Then you can mouse over the available styles, select the dropdown arrow, click Modify..., and change the styles to your liking.

(Tested with Word 2003.)

There is a way. When you define your styles be sure to set TRUE for .ParagraphFormat.KeepTogheter or .ParagraphFormat.KeepWithNext

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top