Link to home
Start Free TrialLog in
Avatar of Galisteo8
Galisteo8

asked on

Need NewPage Section references in VB

I have the following macro from GrahamSkan that I've used to separate a multi-section mail-merged document into individual print jobs:

Sub PrintSectionsSeparately()
    Dim sec As Section
    Dim rng As Range
    For Each sec In ActiveDocument.Sections
        Set rng = sec.Range
        rng.MoveEnd wdCharacter, -1
        rng.Select
        ActiveDocument.PrintOut Range:=wdPrintSelection
    Next sec
End Sub


I now have a new mail-merged document comprised of 2-page letters, and each letter has TWO section breaks: one which is a "continuous" break and is within each letter, and the other which is a "next page" break and separates the letters from eachother.

How can I modify the above macro so that the section references (where the print jobs get separated) apply only to "new page" section breaks?

Thanks,
Galisteo8
Avatar of Galisteo8
Galisteo8

ASKER

Follow-up: I would also need to have each PDF save with a unique name... preferably based on one of the merge fields in the letter, if possible.
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Graham,

With your macro, I do get 2-page print jobs, but the first-page header appears on both pages 1 and 2 of each letter (I think it's the header from the NEXT letter that shows up on page 2).  So I changed the MoveEnd line to be just:

rng.MoveEnd wdCharacter

This gives me page 1 with a header, page 2 without a header... and then a blank page 3!  Except for the last letter in the bunch, which has no blank page 3.

Might there be some way to avoid the hassle of the page 3?
Actually, I can just run a batch process in Acrobat to get rid of the extra page on all the files.
It might be a better idea to simply to disable the line altogether. I moved it back in case a blank page was printed.
'rng.MoveEnd wdCharacter, -1
Moving the point forward would ensure that a character folllowing the next page break was included and would make an extra page a certainty.
Hmmm, removing it still leaves the third page.
OK. The line was there to stop that happening. I think I'll have to think it out again - tomorrow.
Overall, I think the third-page problem lies with the way my original merge document was constructed, i.e. with that extra section break in the header.  Your code, however, does what I needed it to do.  I'll just run a batch process to get rid of the extra pages when/if they occur.

Thanks, Graham.