Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-11-2016, 04:58 AM
gmayor's Avatar
gmayor gmayor is offline Word VBA - "Page left Blank" between Sections to make all Sections start on even page Windows 10 Word VBA - "Page left Blank" between Sections to make all Sections start on even page Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
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

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
__________________
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
  #2  
Old 10-19-2016, 02:15 AM
Cov_ATC Cov_ATC is offline Word VBA - &quot;Page left Blank&quot; between Sections to make all Sections start on even page Windows 7 64bit Word VBA - &quot;Page left Blank&quot; between Sections to make all Sections start on even page Office 2013
Novice
Word VBA - &quot;Page left Blank&quot; between Sections to make all Sections start on even page
 
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
Reply

Tags
automatic, blank page, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word 2010: Section Break "Next" Creates Blank Page Eri Word 11 02-09-2017 03:36 PM
Word VBA - &quot;Page left Blank&quot; between Sections to make all Sections start on even page start SOME sections on new page. drew345 Word 4 12-10-2015 08:34 PM
"Temporary" files that show up on the left of page livemusic Word 4 05-28-2015 04:10 PM
Word VBA - &quot;Page left Blank&quot; between Sections to make all Sections start on even page Mailing: how to make the "page number" in Word is the same as "row number" in excel w Jamal NUMAN Word 1 09-03-2011 11:37 AM
Pesky "Sections Breaks" in word doc Scarlet Word 0 02-09-2011 01:46 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:15 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft