Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Need NewPage Section references in VB

Posted on 2006-05-09
8
Medium Priority
?
233 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:Galisteo8
  • 5
  • 3
8 Comments
 
LVL 8

Author Comment

by:Galisteo8
ID: 16641378
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.
0
 
LVL 77

Accepted Solution

by:
GrahamSkan earned 400 total points
ID: 16642614
Once inserted, the section break type does not seem to be exposed in the object model, so I think that we'll just have to take the sections in pairs.

Sub PrintDoubleSectionsSeparately()
    Dim sec As Section
    Dim rng As Range
    Dim rngStart
    For Each sec In ActiveDocument.Sections
        If sec.Index Mod 2 = 1 Then
            Set rng = sec.Range
        Else
            rng.End = sec.Range.End
            rng.MoveEnd wdCharacter, -1
            rng.Select
            ActiveDocument.PrintOut Range:=wdPrintSelection
        End If
    Next sec
End Sub

0
 
LVL 8

Author Comment

by:Galisteo8
ID: 16642918
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?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
LVL 8

Author Comment

by:Galisteo8
ID: 16643150
Actually, I can just run a batch process in Acrobat to get rid of the extra page on all the files.
0
 
LVL 77

Expert Comment

by:GrahamSkan
ID: 16643197
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.
0
 
LVL 8

Author Comment

by:Galisteo8
ID: 16643443
Hmmm, removing it still leaves the third page.
0
 
LVL 77

Expert Comment

by:GrahamSkan
ID: 16643547
OK. The line was there to stop that happening. I think I'll have to think it out again - tomorrow.
0
 
LVL 8

Author Comment

by:Galisteo8
ID: 16739773
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.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question