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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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?
ASKER
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.
'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.
ASKER
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.
ASKER
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.
Thanks, Graham.
ASKER