View Single Post
  #7   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Setting a print tray

This is all very odd? Testing here I too find that Word 2003 crashes if you
change the default tray in vba with the example used. It certainly didn't do
that when I wrote the web page

One unsatisfactory workaround is to use the following code

Dim sPrinter As String
With Dialogs(wdDialogFilePrintSetup)
sPrinter = .Printer
.Printer = "\\OKKC405\IT_PS.PRINTERS"
.DoNotSetAsSysDefault = True
.Execute
Dialogs(wdDialogFilePrint).Show
.Printer = sPrinter
.DoNotSetAsSysDefault = False
.Execute
End With

which will at least pause while you change the tray manually.

A more in depth look at controlling printers by VBA has been conducted by
fellow MVP Jonathan West - see
http://pubs.logicalexpressions.com/P...cle.asp?ID=116

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org




AJ wrote:
Also, I don't know if this makes any difference, but when I step
through the macro, when it gets to the "With Options . defaulttray"
line 1 of 2 things happens, either it goes through it without the
normal pause you get when it is running a code. Like when it does the
activeprinter line there is a pause while it runs the code and
switches printers, but on this line and the other option line further
in the code it either jumps right through it without any pause Or at
other times when it gets to the option line the program freezes up
and I get the "Word has encountered a problem and must shut down". I
hope this makes since, basically it seems like it either skips over
the "With options" or if it tries to run it I get the Message about
encountering a problem. I don't know if it makes a difference that I
am using Word2003.

"Graham Mayor" wrote:

Oops! By 'below' I meant in the revised macro

Private Sub Document_New()
Dim sCurrentPrinter As String
sCurrentPrinter = Application.ActivePrinter
ActivePrinter = "\\OKKC405\IT_PS.PRINTERS"
With Options
.DefaultTray = "Tray 2"
End With
MsgBox Options.DefaultTray
'Application.PrintOut FileName:=""
With Options
.DefaultTray = "Use printer settings"
End With
ActivePrinter = sCurrentPrinter
End Sub

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



Graham Mayor wrote:
What does the Message Box (below) report?

If, as I suspect, it says Tray 2 - is there a Tray 2 associated with
this printer or is it called something else?

Try setting the tray assignment in the document's page setup (with
the required printer active).


AJ wrote:
I am trying to use a macro on my mail merge template(Word2003) to
set a specific print tray. I am calling the merge from access2003
and then am printing out the new merged document from a module in
access. I am unsuccessful in trying to add a macro I found
(www.gmayor.com/fax_from_word.htm) to place on my template so each
document will print to a different tray. I don't know if I am doing
something wrong or am missing something. I am able to run it from
Word and it will switch the printer but not switch the tray. Then
when I call the whole thing into Access it will switch printers but
not print trays.I have placed the code on the mail merge template
itself in the Document New, because to my limited knowledge this
code is suppose to carry over to the merged documents.Is that
true? I have the code below to view.Thank you ahead for any help.


Private Sub Document_New()
Dim sCurrentPrinter As String
sCurrentPrinter = Application.ActivePrinter
ActivePrinter = "\\OKKC405\IT_PS.PRINTERS"
With Options
.DefaultTray = "Tray 2"
End With
Application.PrintOut FileName:=""
With Options
.DefaultTray = "Use printer settings"
End With
ActivePrinter = sCurrentPrinter
End Sub