A Microsoft Word forum. Microsoft Office Word Forum - WordBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Microsoft Office Word Forum - WordBanter forum » Microsoft Word Newsgroups » Microsoft Word Help
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Adding a blank page if section has odd number of pages (mail merge)



 
 
Thread Tools Display Modes
  #1  
Old March 17th 15, 09:38 AM posted to microsoft.public.word.docmanagement
[email protected]
external usenet poster
 
Posts: 1
Default Adding a blank page if section has odd number of pages (mail merge)

Hello all

Can anyone help me with a macro or something similar to insert a blank page at the end of each letter in a mail merge, if the page number of the last page in that letter (section) is odd? I have tried all kinds of stuff, but just can't get it working. A macro solution where you just run the code after the mail merge would be the best solution for my needs I think. Its all needed because we want to print duplex (double-sided) to save some paper.

Hope someone can help me.

/Jacob
Ads
  #2  
Old March 17th 15, 12:02 PM posted to microsoft.public.word.docmanagement
Peter T. Daniels
external usenet poster
 
Posts: 3,152
Default Adding a blank page if section has odd number of pages (mail merge)

Did you try Insert Section Break New Right-Hand Page?

On Tuesday, March 17, 2015 at 5:38:48 AM UTC-4, wrote:
Hello all

Can anyone help me with a macro or something similar to insert a blank page at the end of each letter in a mail merge, if the page number of the last page in that letter (section) is odd? I have tried all kinds of stuff, but just can't get it working. A macro solution where you just run the code after the mail merge would be the best solution for my needs I think. Its all needed because we want to print duplex (double-sided) to save some paper.

Hope someone can help me.

/Jacob


  #3  
Old March 17th 15, 09:27 PM posted to microsoft.public.word.docmanagement
[email protected]
external usenet poster
 
Posts: 2
Default Adding a blank page if section has odd number of pages (mail merge)

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.
  #4  
Old March 20th 19, 09:01 AM posted to microsoft.public.word.docmanagement
Angie
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.
  #5  
Old March 20th 19, 12:46 PM posted to microsoft.public.word.docmanagement
Peter T. Daniels
external usenet poster
 
Posts: 3,152
Default Adding a blank page if section has odd number of pages (mail merge)

On Wednesday, March 20, 2019 at 5:01:27 AM UTC-4, Angie wrote:

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.


This is for questions about MSWord.

To add a blank page to a pdf, open it in Acrobat and use the "Combine Files"
tool to add in a file you made from a blank Word (or other) document.
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding section names + page number into TOC stickcc Microsoft Word Help 3 December 15th 08 11:13 PM
Section breaks add page number without adding a page rontiara Page Layout 3 January 26th 08 04:38 AM
Blank pages for no reason using page and section breaks Bruce Microsoft Word Help 1 September 19th 07 04:31 PM
page number on blank pages when using section break Howard Hayes Microsoft Word Help 2 October 31st 06 05:08 AM
Page numbering sections with number of pages in that section kjerome New Users 1 February 5th 06 12:36 PM


All times are GMT +1. The time now is 03:24 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright 2004-2019 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.