View Single Post
 
Old 10-11-2016, 04:52 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

create a watermark using one of the built-in watermarks in a new blank document. Open the header and select the Word art. Change the text to 'Page left blank' then while it remains selected ALT+F3 and save it as an autotext entry called 'Blank Page'. The following, based on your code, should then create the blank pages and add the autotext across each.

Code:
Sub PageBreakSectionSeparator()
Dim Sect As Section
Dim iSec As Integer
Dim oRng As Range
Dim iValue As Integer
    With ActiveDocument
        On Error Resume Next
        ' go through each section (except for the last one)
        For iSec = 1 To .Sections.Count - 1
            ' create a range object at the start of the section
            Set oRng = .Sections(iSec).Range
            oRng.Collapse wdCollapseStart
            ' insert a sectionpages field
            .Fields.Add Range:=oRng, Type:=wdFieldSectionPages
            ' divide the sectionpages field by 2
            ' if it gives a zero as the remainder, then
            ' you have an even number of pages in the section,
            ' which is what you want with an odd section page break
            If (.Sections(iSec).Range.Fields(1).Result Mod 2) <> 0 Then
                ' if you have an odd number of pages, then insert
                ' a page break before the section's section break
                Set oRng = .Sections(iSec).Range
                With oRng
                    .Collapse direction:=wdCollapseEnd
                    .MoveEnd unit:=wdCharacter, Count:=-1
                    'Ensure the insertion point is at the end of the text
                    .MoveEndWhile Chr(13) & Chr(32), wdBackward
                    'Insert a page break
                    .InsertBreak Type:=wdPageBreak
                    'Move the insertion point to the blank page
                    .End = .Sections(iSec).Range.End - 1
                    .Collapse direction:=wdCollapseEnd
                    'Insert a building block with the required notification
                    NormalTemplate.BuildingBlockEntries("BlankPage").Insert _
                            Where:=oRng
                End With
            End If
            ' remove the sectionpages field that was added
            .Sections(iSec).Range.Fields(1).Delete
        Next iSec
    End With
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote