h1

Word 2007: Insert an odd page break before each Heading 1

December 15, 2010

I’m testing setting up a template for a potentially very large Word document (hundreds of pages) that will be printed and bound. I want each section/chapter to start on a new, odd page, so I want to associate an odd page section break with my Heading 1 style.

Problem: You can’t do this in Word! You can easily insert a page break before a style, but not a section break. Go figure…

However, you can create a macro that will insert an odd page section break in front of your Heading 1 style. Please note: If you use the Heading 1 style for anything other than your new chapter/section heading, the odd page section break will apply to that too.

The macro below is modified from the one I found here: http://thedailyreviewer.com/windowsapps/view/inserting-a-section-break-before-each-heading-level-1-automatically-10694987

This macro inserts an odd page section break before a Heading 1 style.

Sub  InsertOddPageSectionBreak()
Dim rngDcm As  Range
Dim rngTmp As  Range
Set rngDcm =  ActiveDocument.Range
With  rngDcm.Find
.Style = "Heading  1"
While  .Execute
rngDcm.Select ' for  testing only
Set rngTmp =  rngDcm.Duplicate
rngTmp.Collapse
rngTmp.Select ' for  testing too
If  Asc(rngTmp.Characters.First.Previous) <> 12 And _
Asc(rngTmp.Characters.First)  <> 12 Then
rngTmp.InsertBreak  Type:=wdSectionBreakOddPage
End  If
rngDcm.Collapse  Direction:=wdCollapseEnd
Wend
End  With
End Sub

You can modify it to apply to any named style (replace Heading 1 in the quote marks with any other named style, and you can modify the type of break that’s inserted (e.g. change wdSectionBreakOddPage to wdSectionBreakNextPage).

Thanks to Helmet Weber (Microsoft Word MVP) whose macro pointed me in the right direction.

[Link last checked December 2010]

7 comments

  1. or Microsoft could just make it so that you CAN insert odd page breakes in styles!


  2. […] There are a couple of ways you can add a ‘This page intentionally left blank’ type of message in Word, using VBA code or fields, but neither is particularly easy to implement, especially if you’ve already set up odd page section breaks: […]


  3. Thanks a lot!

    Could you please clarify, why testing:

    If Asc(rngTmp.Characters.First.Previous) 12 And _
    Asc(rngTmp.Characters.First) 12

    Thank you.


  4. Hi Exotic Hadron

    I have no idea what that part of the macro means. I adapted someone else’s macro (see the link), changing the style and the section break type only.

    Rhonda


  5. This macro breaks (crashes) if the first text in the document is of the specified style. Here’s a corrected version:

    Sub InsertOddPageSectionBreak()
        Dim rngDcm As Range
        Dim rngTmp As Range
        Dim check As Boolean
        Set rngDcm = ActiveDocument.Range
        With rngDcm.Find
            .Style = "Heading 1"
            While .Execute
                rngDcm.Select ' for  testing only
                Set rngTmp = rngDcm.Duplicate
                rngTmp.Collapse
                rngTmp.Select ' for  testing too
                check = Asc(rngTmp.Characters.First)  12 And Not (rngTmp.Characters.First.Previous Is Nothing)
                If check Then
                    check = Asc(rngTmp.Characters.First.Previous)  12
                End If
                If check Then
                    rngTmp.InsertBreak Type:=wdSectionBreakOddPage
                End If
                rngDcm.Collapse Direction:=wdCollapseEnd
            Wend
        End With
    End Sub
    

  6. Er, that code should be

    Sub InsertOddPageSectionBreak()
        Dim rngDcm As Range
        Dim rngTmp As Range
        Dim check As Boolean
        Set rngDcm = ActiveDocument.Range
        With rngDcm.Find
            .Style = "Heading 1"
            While .Execute
                rngDcm.Select ' for  testing only
                Set rngTmp = rngDcm.Duplicate
                rngTmp.Collapse
                rngTmp.Select ' for  testing too
                check = Asc(rngTmp.Characters.First) <> 12 And Not (rngTmp.Characters.First.Previous Is Nothing)
                If check Then
                    check = Asc(rngTmp.Characters.First.Previous) <> 12
                End If
                If check Then
                    rngTmp.InsertBreak Type:=wdSectionBreakOddPage
                End If
                rngDcm.Collapse Direction:=wdCollapseEnd
            Wend
        End With
    End Sub
    

  7. It also breaks (loops forever) if the very last text in the document is of the specified style. I’m not quite sure how to fix that one.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: