get Paper Tray

Z

zSplash

I have created a custom document property ("Tray") to value "green" if I
want my document to print on green paper. I have white paper in my top tray
(wdPrinterLowerBin), and green paper in my lower tray (wdPrinterUpperBin).
So, whenever printing, the code checks for the value of "Tray":
If ActiveDocument.CustomDocumentProperties("Tray").Value = "green" Then
With ActiveDocument.PageSetup
.FirstPageTray = wdPrinterUpperBin
.OtherPagesTray = wdPrinterUpperBin
End With
Else
With ActiveDocument.PageSetup
.FirstPageTray = wdPrinterLowerBin
.OtherPagesTray = wdPrinterLowerBin
End With
End If

Is this reasonable, or is there a better way to do what I'm attempting to
do?

TIA, guys.
 
J

Jonathan West

Hi zSplash,

The general approach is sound.

There is a big problem with using the Word constants for this. Different
printer drivers use different values for the various printer trays, and they
almost never match the values of the Word constants. Therefore, you need to
find you what tray ID codes are used for your specific printer, and use
those in place of the Word constants. This article tells you how.

Controlling the Printer from Word VBA
Part 1: Using VBA to Select the Paper Tray
http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=101
 
Z

zSplash

Thanks, Jonathan. So, I did as suggested in your article, and even though I
know there are at least 3 paper trays (the multi-purpose tray, the top tray,
and the bottom tray -- or WHATEVER they're called), the code comes back with
only one iBinArray(0), and only one choice, "FormSelect". Then, when I
select that one option, I get the error:
"Run-time error 4608: Value out of range"
and when I check the code, it's stopped on
ActiveDocument.PageSetup.OtherPagesTray = _
vBinNumbers(ListBox1.ListIndex)
and if I "hover" I see that the statement = False.

Can you make any sense of this?
st.
 
J

Jonathan West

Is the printer connected via a network? If so, do you have a locally
installed copy of the printer driver?

if you do not have a local copy of the driver, install one and try again.
 
Z

zSplash

Thanks so much, Jonathan. You were exactly right -- the driver was not
installed locally.

I have "discovered" the trayID's for one of the 5 printers involved. Seems
sorta goofy, that I would have to locally install the drivers for all of
these printers, and then get the trayID for each bin I need, and then write
code to react to whatever printer is selected. But, this whole thing seems
sorta hokey. Thanks so much for your good code and excellent advice.

st.
 
Z

zSplash

I plea for help yet again...

So, when I run my code using the locally installed driver (for which I have
obtained the proper trayID's), everything's fine. When I switch to the
networked printer, however, evidently the trayID's are "wrong", since the
code does not work. (I.e., my code points to bin 263 and 264 locally, which
prints color and white respectively. When using the network printer, the
exact same code to the exact same printer, but using the network (not the
local driver), the code results in inappropriate output.

Somehow, my reasoning thought if I "got" the trayID's, and then referred to
them in my code, the network printers would "recognize" the same trayID. Is
that faulty reasoning? Is there any reason the driver should not be
installed on the server??? (I am obviously not a network administrator!!)

What do you think the deal is?

st.
 

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