selecting paper trays with VBA

Z

zSplash

So, I am trying something that sounds simple, but is proving difficult (for
me): In my Word document, I want to be able to always have the document
print from the default tray (white paper), unless a custom.document.property
exists -- then, to print from the "color" tray.

Although the "trayID" part of Jonathan West's code consistently showed "0"
for every possible tray, using the firstPage and OtherPages code, I surmise
the trayID for the white and color trays:
White (default) -- 2
Color (Tray 3) -- 11

The trouble is, when I select those trays with code, when my printDialogs
box comes up, and I manually go to Properties, it's clear that the Tray
value has not changed as it should have. Everthing prints from the tray
that was last "selected" by mouse click.

Can someone please help/direct me?

TIA
 
D

Doug Robbins - Word MVP

How about installing a second instance of the printer with its properties
set so that color is the default tray and switch between printers rather
than trays.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
Z

zSplash

Thank you for responding, Doug. I saw that option elsewhere, but didn't
take it, sine there are about 20 network printers involved, which then would
become 40. (!!) Any other suggestions? Is it really such a difficult task
for Word?

st.
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < zSplash > écrivait :
In this message, < zSplash > wrote:

|| Thank you for responding, Doug. I saw that option elsewhere, but didn't
|| take it, sine there are about 20 network printers involved, which then
would
|| become 40. (!!) Any other suggestions? Is it really such a difficult
task
|| for Word?

Do you mean to say that you are trying to write ONE procedure to set the
paper trays for 20 DIFFERENT printers?

If so, no wonders you are having trouble! You have to figure out the
individual printer tray ID's, then do some kind of Case Select in your
code... This is a printer issue, not a Word one. How can Word include
programming objects that will cover the thousands of different printers on
the markets, not courting the new ones that come out after Word has been
released?

I have coded something like this for a client that also had many networked
printers. We had an understanding that the code I wrote was going to
automatically select a specific printer and use its 6 trays. So all I had to
do was select the printer and according to the user choice, activate one (or
two) of its 6 trays.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jonathan West

zSplash said:
Thank you for responding, Doug. I saw that option elsewhere, but didn't
take it, sine there are about 20 network printers involved, which then would
become 40. (!!) Any other suggestions? Is it really such a difficult task
for Word?

Some questions.

1. Are the printers all of identical make & model?
2. Are the operating systems in use all the same everywhere?
3. Is the same version of the printer driver in use everywhere?
4. Have you attempted on your test machine to create a local installation of
the printer driver for each of the models of network printer?
 
Z

zSplash

Thanks for your help, Jonathan.

1. The printers are of 4 types: HP4200, HP4, HP4050, HP4050TN.
2. All operating systems are Win2k.
3. Same version of the printer driver for each type.
4. With your good suggestion, I did a local installation of the HP4200
driver, got the tray ID's, works fine. Then (after changing the printer
definition on the server) was able to get the tray = "", trayID=0,
firstPageID=2, otherPagesID=2 for the printer on the server. The trouble
is, with both locally installed printer and the network printer:
"when I select those trays with code, when my printDialogs
box comes up, and I manually go to Properties, it's clear that the Tray
value has not changed as it should have. Everything prints from the tray
that was last "selected" by mouse click."

I wonder whether the default tray was not set correctly by the server
definition, but this probably isn't the forum to wonder about that.....

Thanks for any help you can give me, Jonathan.

st.
 
Z

zSplash

Here is the code I'm using to select the tray:
If ActiveDocument.CustomDocumentProperties("Tray").Value = "green" Then
With ActiveDocument.PageSetup
.FirstPageTray = 11
.OtherPagesTray = 11
End With
Else
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With
End If

I got 2 and 11 as the values for "Tray 3" and "Tray 2" using your code.

st.
 
J

Jonathan West

zSplash said:
Thanks for your help, Jonathan.

1. The printers are of 4 types: HP4200, HP4, HP4050, HP4050TN.

Each one is likely to have different tray IDs. You will have to do a local
installation of each type of printer in order to find out what they are.
2. All operating systems are Win2k.
3. Same version of the printer driver for each type.

That reduced the number of permutations you have to address :)
4. With your good suggestion, I did a local installation of the HP4200
driver, got the tray ID's, works fine. Then (after changing the printer
definition on the server) was able to get the tray = "", trayID=0,
firstPageID=2, otherPagesID=2 for the printer on the server. The trouble
is, with both locally installed printer and the network printer:
"when I select those trays with code, when my printDialogs
box comes up, and I manually go to Properties, it's clear that the Tray
value has not changed as it should have. Everything prints from the tray
that was last "selected" by mouse click."

I wonder whether the default tray was not set correctly by the server
definition, but this probably isn't the forum to wonder about that.....

Thanks for any help you can give me, Jonathan.

Some possibilities come to mind.

1. The ActivePrinter property may not be set correctly. For this purpose,
don't use the workaround on the MVP site that allows you to change printers
without changing the ActivePrinter.

2. Try setting the trays manually in the Page Setup dialog, and see if it
prints correctly. If it does, then what we may have is some timing problems.
Try solving those by putting 5 or 6 DoEvents commands immediately after
setting the trays in code.

3. If it won't print right after setting the trays manually, then you may
need to do a local installation of the printer driver for all PCs that run
your macro.
 
Z

zSplash

FYI, guys, here's a work around for this problem (at least in my case).
There's a shareware program called "AutoHotKey" that allowed me to write a
script to print from the green tray . Now, I have an icon in the taskbar
that the user clicks when they desire green paper.

What's a link to MS to suggest the next version of Word or VBA "fix" this
annoying problem with paper trays/trayID/defaultTray/OtherTray, etc? (or,
at least, that VBA have the some of the same methods as VB in this
regard)...

st.
 
J

Jay Freedman

What's a link to MS to suggest the next version of Word or VBA "fix"

Send it to (e-mail address removed). You won't be the first or last with this
suggestion. :)
 

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