View Single Post
 
Old 10-19-2016, 02:15 AM
Cov_ATC Cov_ATC is offline Windows 7 64bit Office 2013
Novice
 
Join Date: Oct 2016
Posts: 5
Cov_ATC is on a distinguished road
Default

Thank you very much for your help,
I apologise for late reply,
I was on leave.
I will try the code asap and let you know the outcome.

Regards,

Cov_ATC









Quote:
Originally Posted by gmayor View Post
On reflection the field should not be necessary try the following instead
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
            If .Sections(iSec).Range.Information(wdActiveEndPageNumber) 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
        Next iSec
    End With
End Sub
Reply With Quote