View Single Post
  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Angie Angie is offline
external usenet poster
 
Posts: 1
Default Adding a blank page if section has odd number of pages (mail merge)

On Tuesday, March 17, 2015 at 9:27:32 PM UTC, wrote:
I don't know what type of section break you are thinking about, but I have made some progress, but with a slightly different approach:

This is the code used:

Sub CheckSecLen()
Dim iSec As Integer
Dim oRng As Range
Dim iValue As Integer

With ActiveDocument
' 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
.InsertBreak Type:=wdPageBreak
.InsertBreak Type:=wdPageBreak
End With
End If
' remove the sectionpages field that was added
.Sections(iSec).Range.Fields(1).Delete
Next iSec
End With
End Sub

If you notice, I had to put two wdPageBreak's in, to make it work for me. I have also inserted some code after the last End With command (which is not included in the code above) that finds the last page and then pressed the arrow back (delete like button above the Return), so that the last page that is strangely added at the end of the document is removed.

Not the way I thought it should be done, but it seems to work.


Hello: I am trying to do the same as Jacob with the exception that my document is an Adobe PDF (due to its size we spool it in PDF format). Can I get assistance adding a blank page if the last page of my letter is odd? Thank you in advance.