word vba to select paper trays based on activeprinter

K

kurt

I've looked on line at several places and then put the following code into a
word macro. It doesn't switch trays based on the active printer. Can
someone please help?

Thanks!

Kurt

Sub testprint()
If ActivePrinter = "\\FS01\HelpDesk-HP4000" Then
With ActiveDocument.PageSetup
.FirstPageTray = 260
.OtherPagesTray = 261
End With

ElseIf ActivePrinter = "\\Fs01\9st3_HP4300" Then
With ActiveDocument.PageSetup
.FirstPageTray = wdPrinterLowerBin
.OtherPagesTray = wdPrinterUpperBin
End With

Else
With ActiveDocument.PageSetup
.FirstPageTray = 0
.OtherPagesTray = 0
End With
End If
End Sub

*************************************************
I've also tried the Case scenerio, which also doesn't work either:

Select Case Application.ActivePrinter
Case "\\FS01\HelpDesk-HP4000"
With ActiveDocument.PageSetup
.FirstPageTray = 260
.OtherPagesTray = 261
End With

Case "\\Fs01\9st3_HP4300"
With ActiveDocument.PageSetup
.FirstPageTray = wdPrinterLowerBin
.OtherPagesTray = wdPrinterUpperBin
End With
Case Else
With ActiveDocument.PageSetup
.FirstPageTray = 0
.OtherPagesTray = 0
End With
End Select
 
R

Russ

Kurt,
Does
Msgbox activeprinter
equate to one of the strings you are testing against?
Have you single-stepped through the macro to see where it is going?
 
J

Jean-Guy Marcil

kurt was telling us:
kurt nous racontait que :
I've looked on line at several places and then put the following code
into a word macro. It doesn't switch trays based on the active
printer. Can someone please help?

Thanks!

Kurt

Sub testprint()
If ActivePrinter = "\\FS01\HelpDesk-HP4000" Then
With ActiveDocument.PageSetup
.FirstPageTray = 260
.OtherPagesTray = 261
End With

ElseIf ActivePrinter = "\\Fs01\9st3_HP4300" Then
With ActiveDocument.PageSetup
.FirstPageTray = wdPrinterLowerBin
.OtherPagesTray = wdPrinterUpperBin
End With

Else
With ActiveDocument.PageSetup
.FirstPageTray = 0
.OtherPagesTray = 0
End With
End If
End Sub

Second try... Ireplies yesterday, but I do not see my post...

Usually, ActivePrinter returns the port as well, so you would need something
like:

If ActivePrinter = "\\FS01\HelpDesk-HP4000 on NE06:" Then

--

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

kurt

Russ,

Thank you SO much for your reply. I added your code to my macro and
discovered that the name of my printers were not correct. A total lifesaver.

Many, many thanks!

Kurt
 
K

kurt

Jean-Guy,

Thanks for your reply. I first tried your answer in my code, which didn't
actually work, but it gave me a piece that was missing. Then I tried the
bit of code from Russ' reply, which solved the problem. My printer names
were incorrect, including a ":"! Thanks to both of you!!

Merci mille fois!!

Kurt
 
J

Jean-Guy Marcil

kurt was telling us:
kurt nous racontait que :
Jean-Guy,

Thanks for your reply. I first tried your answer in my code, which
didn't actually work, but it gave me a piece that was missing. Then
I tried the bit of code from Russ' reply, which solved the problem.
My printer names were incorrect, including a ":"! Thanks to both of
you!!

Glad you worked it out. By the way, I did not post that code for you to use,
but as an example... I guess I should have been clearer!

--

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

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