Moving Headings to the Next Page

by Allen Wyatt
(last updated October 9, 2015)

3

Bruce would like to have any Heading 1 paragraphs start at the top of the next page if they would otherwise fall into the lower 1/3 of the previous page. He wonders if there is a way to do this, perhaps with a macro.

Word has a built-in capability to adjust pagination based on the characteristics of a paragraph. (A heading is a type of paragraph, so this applies to headings just as easily as it does to any other type of paragraph.) On the Line and Page Breaks tab of the Paragraph dialog box you can see these three settings:

  • Page Break Before. This setting, when chosen, forces the paragraph to always start at the top of the next page.
  • Widow/Orphan Control. This setting, when chosen, ensures that if a paragraph requires multiple lines, a single line of the paragraph won't be left alone at the bottom or top of a page. Even though most headings are single lines, this is a handy setting for headings in case they require multiple lines.
  • Keep with Next. This setting, when chosen, ensures that the paragraph stays with the paragraph that follows it. This is great for a heading, as it ensures that a heading must be with at least two lines of the paragraph that follows it. (This presumes that you have the following paragraph formatted for Widow/Orphan Control.)

While these controls are fantastic, they won't meet Bruce's needs because none of them will force a heading to the next page if it would normally appear in the bottom third of a page. This means that Bruce needs to come up with a workaround that will accomplish what he wants.

One approach is to define two Heading 1 styles. One of the styles could be considered "normal," meaning that it will appear in the normal flow of your document text. The other style could be based on the regular Heading 1, but it could have the Page Break Before setting (discussed earlier) enabled. These two styles would be very easy to use; all you need to do is make sure that all regular Heading 1 styles are used throughout the document. Then, before printing, you could manually go through the document, one page at a time, and apply the secondary Heading 1 style to those headings that are too far down the page for your liking. They would automatically be moved to the top of the next page, Word would repaginate the document, and you could continue scanning for headings that needed to be moved.

The reverse approach would be to actually place manual page breaks before all your Heading 1 paragraphs. If you then select the page break and Heading 1 paragraph, you could define it as a building block that you could later use for all your headings. (Just insert the building block and then modify the text in the actual heading paragraph.) Before printing, manually go through the document and, if you see that a heading could be moved to the preceding page, delete the page break that is just in front of the heading paragraph. Word moves the heading to the preceding page, repaginates the document, and you could continue scanning for headings that could be moved.

If the lower third of a page is not deeper than 10 lines of text, then you could use a rather novel approach to your headings: Format them with a drop cap. A drop cap can be up to 10 lines deep; all you need to do is make sure that the "dropped" character is something that is very, very thin. For instance, you might try using an uppercase letter I. Format the single character as a very small point size and make its color white. Then select the character and make it a 10-line drop cap. If the entire drop cap cannot fit on the page, Word obligingly moves it to the next page. You may have to play with some of the formatting characteristics to get exactly what you want, but it is the only potential workaround that doesn't involve any manual processing on your part.

If you want to use a macro to do the formatting, the most practical approach is to have the macro adjust the positions of any Heading 1 paragraphs after the document is complete. The idea is for the macro to search from the beginning of the document, looking for any Heading 1 paragraphs. If one is found and it is positioned at more than 66% of the page height, then a page break is inserted to move the heading to the next page. The following macro performs all these tasks.

Sub AdjustHeading()
    Dim CursorVert As Single
    Dim Pgheight As Single
    Dim styleName As String

    styleName = "Heading 1"
    If ActiveDocument.Styles(styleName).ParagraphFormat.PageBreakBefore Then
        MsgBox styleName & " has 'Page break before' set. Run aborted"
        Exit Sub
    End If
    Selection.HomeKey unit:=wdStory
    With Selection.Find
        .ClearFormatting
        .Style = ActiveDocument.Styles(styleName)
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
    End With
    Do While Selection.Find.Execute
        If Asc(Selection.Range.Characters(1)) = 12 Then
            Selection.MoveStart unit:=wdCharacter, Count:=1
        End If
        With ActiveDocument.Sections(Selection.Information(wdActiveEndSectionNumber)).PageSetup
            CursorVert = Selection.Information(wdVerticalPositionRelativeToPage) - .TopMargin
            Pgheight = .PageHeight - .TopMargin - .BottomMargin
        End With
        If CursorVert > Selection.Style.ParagraphFormat.SpaceBefore Then
            If CursorVert / Pgheight > 0.66 And Len(Selection.Range) > 1 Then
                Selection.End = Selection.Start
                Selection.TypeText Chr(12)
            End If
        End If
        Selection.Start = Selection.End
    Loop
End Sub

In order for this macro to operate properly, you should make sure that your Heading 1 style doesn't have the Page Break Before attribute set. The macro determines the page height of the current section to accommodate documents that vary page height from section to section. Page height is calculated by subtracting the top and bottom margins from the paper height.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (12564) applies to Microsoft Word 2007, 2010, and 2013.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Disabling a Function Key

Function keys are used to perform common tasks in Excel. If you want to disable one of the function keys, it's rather easy to ...

Discover More

Extracting URLs from Hyperlinked Images

When copying information from the Internet to an Excel workbook, you may want to get rid of graphics but keep any hyperlinks ...

Discover More

Creating a Custom Power Management Plan

Don't like the built-in power management plans that Windows provides? You can create your own to better fit your power needs.

Discover More

Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!

More WordTips (ribbon)

Creating an Inline Heading

When settling on an overall design for your document, you need to decide how you want your headings to appear. If you want ...

Discover More

Formatting All Headings At Once

If you need to apply a common formatting change to all the headings in your document, a quick way to do it is to use the ...

Discover More

Getting the Expected Space Before a Heading

If your heading styles are designed to add extra space before the heading, you may be surprised when that extra space is not ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 8Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 5 + 0?

2015-10-21 09:59:31

Ueli

Thanks, great tipp! That's exactly what I was looking for.


2015-09-23 03:44:07

Jarrod

Super helpful, thanks!


2013-03-23 04:41:51

Dr. Bartolo

As I understand it this macro will only work once, so if the document has to go through more than one version before it is finalised something else would be needed.

One possibility for the second and each subsequent version of the document would be to do a search and replace (search for each page break and replace it with nothing) first, followed by re-running the macro.

The problem with that is that all other page breaks would also be lost.

Perhaps the macro could be amended to give an option to run the search and replace routine first (to be skipped if there is only one version of the document). It could also perhaps be written to allow the user to choose whether or not to replace a page break as it finds it.

I am afraid that writing macros is beyond me, so I cannot help with actual proposed code.


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.