VBA Section Printing Problem in MSWord (Printout method)

R

RacinMyLancer

I am having trouble telling the Printout method (VBA, MS Word 2002) to print
specific SECTIONS of my document only. I have attempted several different
techniques and have concluded that the method has trouble interpreting page
ranges... although I would be glad to find out that I am mistaken.

So: I have a document with 4 sections, page numbers as follows: s1(3),
s2(3), s3(1), s4(1).

I employ the following line of code:
Code:
ActiveDocument.PrintOut Background:=True, Range:=wdPrintFromTo,
From:=vPrintRangeLower, To:=vPrintRangeHigher, Copies:=1

,where vPrintRangeLower and vPrintRangeHigher are defined as the upper and
lower page ranges of my document. In this case, they are set to 1 and 3, for
the first section of the document.

The result is, the ENTIRE 8 page document prints out.

So I set my ranges to 4-6, to print the second section... the result is the
same... the ENTIRE document prints out.

I also attempted the following line of code, bypassing 'wdPrintFromTo':
Code:
ActiveDocument.PrintOut Background:=True, Pages:="s" & M, Copies:=1
,where M=the current section, ie. 1,2, so that the print ranges read "s1",
"s2", etc.

The result is exactly the same. The entire document prints out. The
PrintOut method works perfectly for me in documents that are not divided into
sections, so my conclusion is either that the PrintOut method is not capable
of properly interpreting and handling sections, OR... there's something I'm
doing wrong.

I would REALLY love some input. Thanks in advance.
 
T

Tony Jollans

When you specify pages to print you must ensure that the page numbers you
use uniquely reference the page(s) you want to print. When you have multiple
page 1's you must qualify each with section, so with this ...

ActiveDocument.PrintOut Background:=True, Range:=wdPrintFromTo, _
From:=vPrintRangeLower, To:=vPrintRangeHigher, Copies:=1

vPrintRangeLower needs to be "p1s1" and vPrintRangeHigher "p3s1", for
example.

Just using "p1" and "p3" as you were, prints all pages numbered 1, 2 or 3 -
in your case the whole document.
 
R

RacinMyLancer

Thanks so much, Tony. Such a simple solution, can't believe I overlooked it.
Worked like a charm!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top