Paper Bins by DriverName

J

JayM

Hi
I am trying to create a macro across offices with various printer drivers to
automate printing to certain bins.

Can anyone please tell me if the below code is likely to work or suggest
anything that will. The names of each printer differ on each pc but the
driver names won't

Sub DriverThick()
sDriver = DriverName
If InStr(sDriver, "HP Laserjet 4000 Series PCL6") > 0 Or InStr(sDriver, "HP
Laserjet 4000 Series PCL5e") Then
With ActiveDocument.PageSetup
.FirstPageTray = wdPrinterLargeCapacityBin
.OtherPagesTray = wdPrinterLargeCapacityBin
End With
ElseIf InStr(sDriver, "SHARP MX-4500N PCL5c") > 0 Or InStr(sDriver, "SHARP
AR-M450 PCL6") Then
With ActiveDocument.PageSetup
.FirstPageTray = 258
.OtherPagesTray = 258
End With
ElseIf InStr(sDriver, "SHARP AR-M450U PCL6") > 0 Then
With ActiveDocument.PageSetup
.FirstPageTray = wdPrinterMiddleBin
.OtherPagesTray = wdPrinterMiddleBin
End With
End If
' Application.PrintOut filename:="", Range:=wdPrintAllDocument,
Item:=wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False

End Sub


Many thanks
 
J

Jonathan West

In principle, this can work, provided that "DriverName" is the name of a
function that obtains the driver name of the current printer. That is the
hard bit! you haven't provided the code for that function. I'm not sure
whether this is because you have it but didn't include it, or whether you
want help with writing that function.
 
J

JayM

Jonathan
Thanks for replying - I am slowly trying to work my way around this VBA lark
- I just wish I could find a decent course in the UK to help me!! If you know
of any please let me know.

I pieced the original macro together from another forum but used the
following macro
Sub blah()
MsgBox "Driver Name is " & _
GetPrinterDetails.DriverName

End Sub

to obtain the name of the drivers off my pc. This I obtained from your very
useful Techtrax notes.

I suppose I just need help then understanding what I have put together and
getting it to work!!

Any help would be appreciated

Many thanks
JayM
 
J

Jonathan West

JayM said:
Jonathan
Thanks for replying - I am slowly trying to work my way around this VBA
lark
- I just wish I could find a decent course in the UK to help me!! If you
know
of any please let me know.

I pieced the original macro together from another forum but used the
following macro
Sub blah()
MsgBox "Driver Name is " & _
GetPrinterDetails.DriverName

End Sub

to obtain the name of the drivers off my pc. This I obtained from your
very
useful Techtrax notes.

Can I assume that you have tested that function within your code and that it
is returning the correct driver name?
I suppose I just need help then understanding what I have put together and
getting it to work!!

The next part of it is checking the tray IDs for the various printers you
support. I would recommend you completely ignore all the predefined Word
constants, they apply to almost no printers at all.

What you need to do is find out what paper trays are available on each
printer, which Tray IDs they have, and then of those, which one you want to
use for each printer. The following article includes code for getting the
complete list of tray names and IDs from a printer.

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

It might be an idea to extend that code to print a page from each tray in
turn, so you can be sure which tray ID maps to each physical tray. (It often
happens that a tray has more than one ID that points to it.)

I think you are nearly there, and a bit more effort will get you over the
finishing line :)
 
J

JayM

Jonathan
Thank you for your reply.

I have checked my printer drivers and I am getting good returns for my
drivername.
Unfortunately I can't know see the finishing line because I have grit in my
eyes for falling at the second hurdle;-)

I have used your code to obtain the tray names but when I try to use these
in my macro it just prints eveything to the same tray even though I have
requested different trays.

Would be grateful for a further nudge in the right direction.

Jay
 
J

Jonathan West

JayM said:
Jonathan
Thank you for your reply.

I have checked my printer drivers and I am getting good returns for my
drivername.
Unfortunately I can't know see the finishing line because I have grit in
my
eyes for falling at the second hurdle;-)

I have used your code to obtain the tray names but when I try to use these
in my macro it just prints eveything to the same tray even though I have
requested different trays.

Would be grateful for a further nudge in the right direction.

Show us the code you are using to print from the different trays.
 
J

JayM

Jonathan
My code is as follows:
Sub DriverLH()
sDriver = DriverName
If InStr(sDriver, "HP Laserjet 4000 Series PCL6") > 0 Or InStr(sDriver, "HP
Laserjet 4000 Series PCL5e") Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With
ElseIf InStr(sDriver, "SHARP MX-4500N PCL5c") > 0 Or InStr(sDriver, "SHARP
AR-M450 PCL6") Then
With ActiveDocument.PageSetup
.FirstPageTray = 259
.OtherPagesTray = 259
End With
ElseIf InStr(sDriver, "SHARP AR-M450U PCL6") > 0 Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With
End If
Application.PrintOut filename:="", Range:=wdPrintAllDocument,
Item:=wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False

End Sub
I have tried playing around with this but I just can't get it to work

Many thanks

JayM
 
J

Jonathan West

JayM said:
Jonathan
My code is as follows:

Sub DriverLH()
sDriver = DriverName
If InStr(sDriver, "HP Laserjet 4000 Series PCL6") > 0 Or InStr(sDriver,
"HP
Laserjet 4000 Series PCL5e") Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With
ElseIf InStr(sDriver, "SHARP MX-4500N PCL5c") > 0 Or InStr(sDriver, "SHARP
AR-M450 PCL6") Then
With ActiveDocument.PageSetup
.FirstPageTray = 259
.OtherPagesTray = 259
End With
ElseIf InStr(sDriver, "SHARP AR-M450U PCL6") > 0 Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With
End If
Application.PrintOut filename:="", Range:=wdPrintAllDocument,
Item:=wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, Collate:=True, Background:=True,
PrintToFile:=False

End Sub

I have tried playing around with this but I just can't get it to work

Two possible problems occur to me.

1. Check your If statements.
In each of the first two, you are comparing the driver name with two
different references, but you are only comparing the output of the Instr
function to the first reference with zero. Have you tried stepping through
the code to make sure that you are actually following the right branches?

2. Don't background print.
Background printing and the code to control the printer doesn't go well
together. Set the Background parameter to False.
 
T

Tony Strazzeri

Jonathan
My code is as follows:



Sub DriverLH()
sDriver = DriverName
If InStr(sDriver, "HP Laserjet 4000 Series PCL6") > 0 Or InStr(sDriver, "HP
Laserjet 4000 Series PCL5e") Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With
ElseIf InStr(sDriver, "SHARP MX-4500N PCL5c") > 0 Or InStr(sDriver, "SHARP
AR-M450 PCL6") Then
With ActiveDocument.PageSetup
.FirstPageTray = 259
.OtherPagesTray = 259
End With
ElseIf InStr(sDriver, "SHARP AR-M450U PCL6") > 0 Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With
End If
Application.PrintOut filename:="", Range:=wdPrintAllDocument,
Item:=wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False

End Sub



I have tried playing around with this but I just can't get it to work

Many thanks

JayM

One additional thing to keep in mind is that the problem may be at the
printer end. I have done this sort of thing quite a bit and learned
two things to I would like to pass on for the benefit of others.

1. If the printer driver is a PostScript driver (its not in your
case), I have come across some versions where the tray selectioncodes
were simply ignored by the printer.

2. Some printers will also ignore tray selections sent this way if
ther printer itself is doing some tray management eg matching paper
size to trays. If your code is OK try changing the printer
configuration so it doesn't do tray management.


Hope this helps.

Cheers
TonyS.
 
J

JayM

Hi
Still can't get this to work - really wish I understood all of the code I
was trying to work with!!
I have tried :
Sub DriverLH()
sDriver = DriverName
If InStr(sDriver, "HP Laserjet 4000 Series PCL6") Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With
ElseIf InStr(sDriver, "HP Laserjet 4000 Series PCL5e") Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With
ElseIf InStr(sDriver, "SHARP MX-4500N PCL5c") Then
With ActiveDocument.PageSetup
.FirstPageTray = 259
.OtherPagesTray = 259
End With
ElseIf InStr(sDriver, "SHARP AR-M450 PCL6") Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With
ElseIf InStr(sDriver, "SHARP AR-M450U PCL6") Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With
Else: MsgBox "Blah blah blah", vbOKOnly
End If
Application.PrintOut filename:="", Range:=wdPrintAllDocument,
Item:=wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, Collate:=True, Background:=False,
PrintToFile:=False
End Sub

This just brings up the message box and then prints the page but on thin
white paper no matter which try is selected.

Where am I going wrong.

With my original code my if statements had ">0" after the first printer
driver but I don't really understand what this is supposed to do.

Any guidance would be appreciated (can you recommend any courses or books)

Many thanks
 
J

Jonathan West

JayM said:
Hi
Still can't get this to work - really wish I understood all of the code I
was trying to work with!!
I have tried :
Sub DriverLH()
sDriver = DriverName

It is probably worth checking at this point that sDriver does in fact
contain the string you expect it to i.e. that DriverName() has returbned the
correct value for the driver of the current printer.
If InStr(sDriver, "HP Laserjet 4000 Series PCL6") Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With
ElseIf InStr(sDriver, "HP Laserjet 4000 Series PCL5e") Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With
ElseIf InStr(sDriver, "SHARP MX-4500N PCL5c") Then
With ActiveDocument.PageSetup
.FirstPageTray = 259
.OtherPagesTray = 259
End With
ElseIf InStr(sDriver, "SHARP AR-M450 PCL6") Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With
ElseIf InStr(sDriver, "SHARP AR-M450U PCL6") Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With
Else: MsgBox "Blah blah blah", vbOKOnly
End If
Application.PrintOut filename:="", Range:=wdPrintAllDocument,
Item:=wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, Collate:=True, Background:=False,
PrintToFile:=False
End Sub

This just brings up the message box and then prints the page but on thin
white paper no matter which try is selected.

In that case, the driver name is not matching any of the special cases you
have defined. Change the line that displays the messagebox to somethinmg
informative, like this

Else: MsgBox "Driver name is: " & sDriver, vbOKOnly

Where am I going wrong.

With my original code my if statements had ">0" after the first printer
driver but I don't really understand what this is supposed to do.

The Instr function returns a Long. It is zero if the second string is not
found within the fiurst, and it returns a positive number indicating the
position of the first character of the second string within the first
string. If all you want to do is check that the second string is *somewhere*
in the first, then you can compare the value with zero.
 
J

JayM

Sorted it!!!!

Stupid mistake really forgot GetPrinterDetails bit from the sDriver line!!!!!

Could I be more efficient with my code

Thanks again for all your help with this - changing the message box to be
more helpful certainly was more helpfull

Sub DriverLH()
sDriver = GetPrinterDetails.DriverName
If InStr(sDriver, "HP LaserJet 4000 Series PCL 6") Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With

ElseIf InStr(sDriver, "HP LaserJet 4000 Series PCL 5e") Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With

ElseIf InStr(sDriver, "SHARP MX-4500N PCL5c") Then
With ActiveDocument.PageSetup
.FirstPageTray = 259
.OtherPagesTray = 259
End With

ElseIf InStr(sDriver, "SHARP AR-M450 PCL6") Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With

ElseIf InStr(sDriver, "SHARP AR-M450U PCL6") Then
With ActiveDocument.PageSetup
.FirstPageTray = 2
.OtherPagesTray = 2
End With

Else: MsgBox "Driver Name is: " & sDriver, vbOKOnly

End If
Application.PrintOut filename:="", Range:=wdPrintAllDocument,
Item:=wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, Collate:=True, Background:=False,
PrintToFile:=False


End Sub
 
J

Jonathan West

JayM said:
Sorted it!!!!

Stupid mistake really forgot GetPrinterDetails bit from the sDriver
line!!!!!

You might like to take a look at this article to help you avoid (or at least
more quickly detect) such problems in future.


Why variables should be declared properly
http://www.word.mvps.org/FAQs/MacrosVBA/DeclareVariables.htm
Could I be more efficient with my code

If you take the advice in that article, and use Option Explicit at the start
oif each module, then you would want to declare sDriver at the start of the
routine. Declare it As String rathyer than as Variant. It makes little
difference in this case, but dealing with strings is usually a bit quicker
than dealing with variants.

Thanks again for all your help with this - changing the message box to be
more helpful certainly was more helpfull

Glad you got it fixed in the end :)
 
J

JayM

Jonathan
Thanks again so much for your help with my macros they work a treat now.

My next challenge is that we have some offices working over citrix using a
Citrix Universal Printer driver. Have you any ideas how I could get my
macros to work with these.

JayM
 
J

Jonathan West

JayM said:
Jonathan
Thanks again so much for your help with my macros they work a treat now.

My next challenge is that we have some offices working over citrix using a
Citrix Universal Printer driver. Have you any ideas how I could get my
macros to work with these.

Ouch! I tend to shudder somewhat whenever I learn that my templates are
goijg to have to work over Citix - it always seems to cause additional
problems.

I think the first thing to find out is whether the existing
GetPrinterDetails code will work with the Citrix universal driver. If so,
the problem is simply to work out what tray IDs you need to use.

If the GetPrinterDetails code *doesn't* work, then you need to think of a
way in which a Citrix universal driver can be distinguished from a "real"
printer. So long as there is some means of making that distinction, then you
can assign tray IDs accordingly.

However, there is one further wrinkle you might need to consider. The Citrix
universal driver presumably is managing print queues rather than individual
printers, and the Citrix server in fact has conventional printer drivers
which manage the physical printers, and print jobs are passed to the
conventional driver by the Citrix universal driver. The Citrix universal
driver might simply pass through the tray IDs to the conventional driver, in
which case you will have to follow one of two possible routes.

1. Ensure that all the printers associated with a particuar identifiable
Citrix queue are of the same known type, so you can use known tray IDs when
printing to that queue.

2. Find some way of identifying the physical printer to be used, and setting
the tray IDs accordingly.

Without knowledge of your particular system, I don't think I can offer any
more specific advice than this.
 
J

JayM

Ok so the citrix thing I will have to think about then!!!

On a slightly different note. I have been looking at your article for
printing duplex which works great except ......
when using pre-printed letterheads to print double sided.
In our sharp printer/copiers it is not a problem but with the HP Laserjets
you have to tell it to print with the paper rotated.
Is there anyway to control this using vba?

JayM
 
J

Jonathan West

JayM said:
Ok so the citrix thing I will have to think about then!!!

On a slightly different note. I have been looking at your article for
printing duplex which works great except ......
when using pre-printed letterheads to print double sided.
In our sharp printer/copiers it is not a problem but with the HP Laserjets
you have to tell it to print with the paper rotated.
Is there anyway to control this using vba?

The second article in the series describes how to control the duplex setting
of the printer. Different values determine which way up the text is printed
on the reverse side. Since I wrote the article, I have come across an
occasional printer that has nonstandard values for the Duplex property, so
you'll need to check that out. Try setting the duplex property by hand
through the printer properties dialog so that it prints the way you want,
and then use code to read the resulting value of the duplex setting.
 
J

JayM

Jonathan
Thanks for the reply.
Unfortunately I still can't get it to work.
Because of the pre-printed letterhead on the HP printers we need to Rotate
the paper (Rotated is an option on the Basics tab in the printing
preferences).

I have searched and searched for info on this but can't find it - do you
know where I might be able to get advice on this one

At the moment I have a macro that stops so the user can change printer(or
profile) with the duplex and rotated settings on and then stops after the
print to reset it.

JayM
 
J

JayM

Jonathan
Many thanks for all your help with my many printing queries - unfortunately
I have another one for you.
I have written a macro to use your duplexing code and this works fine
locally but when using word in Citrix it seems to ignore the duplex code. At
the moment Citrix just has a universal driver and each pc has the printer
installed locally if this is of any help.

JayM
 

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