Select a printer

B

BruceM

I posted a question a few days ago, but perhaps I made the question overly
complex, and did not receive a reply.

I have code that selects pages to print based on bookmarks. The pages to
print have a watermark that is part of the document (i.e. not inserted by
code at run time).

I know that I can invoke the Print dialog in code, and thereby select a
printer, but that will cause the entire document to print. However, the
watermark mentioned above needs to be in color, so I would like a way to
select a color printer (if it is not the default) without printing the whole
document. Any ideas on how to approach this? Best may be to check if the
default printer is on a list of color printers, and to use a different
printer if it is not, or something like that. All color printers have
"color" in the name, if that helps.
 
S

Steve Yandl

Try something like what I have below. This will not change the system
default printer but you may want to capture the name of ActivePrinter so you
can restore it after you do the printout of the pages.

Sub PrintThisInColor()
Dim strColorPrinter As String

strColorPrinter = "hp psc 2500 series"

If Not InStr(ActivePrinter, "color") > 0 Then
With Dialogs(wdDialogFilePrintSetup)
.Printer = strColorPrinter
.DoNotSetAsSysDefault = True
.Execute
End With
End If

ActiveDocument.PrintOut

End Sub


Steve Yandl
 
B

BruceM

Thanks to both for your help. A bunch of stuff came up this afternoon, so I
haven't had a chance to test any of this yet, but it is encouraging that the
ActiveDocument.PrintOut line happens after the printer has been assigned. I
have that line in my code, but havent' been able to get that far before the
printer starts to print the whole document. I have only had a chance to
take a quick look at the links, but they too seem to have information that
can be put to use either for this project or another. The problem of
capturing printer information as variables has come up from time to time.
I'll post back after I have had a chance to test this out, probably on
Monday. Thanks again.
 
G

Graham Mayor

This thread prompted me to resurrect an old theme of my own for
http://www.gmayor.com/fax_from_word.htm which I had never got around to.

Combined with the code at
http://word.mvps.org/FAQs/MacrosVBA/AvailablePrinters.htm to list the
available printers in an array, the following routine will locate a color
printer (using the name Color - though it could find any text string in the
required printer) and sets that as active printer for the duration of the
print, before returning the original printer as active printer. By the time
you have enjoyed your weekend break I should have added this to the page on
my web site :)

Sub PrintColor()
Dim StrPrinters As Variant, i As Long
Dim sPrinter As String
StrPrinters = ListPrinters
sPrinter = ActivePrinter
If IsBounded(StrPrinters) Then
For i = LBound(StrPrinters) To UBound(StrPrinters)
If InStr(UCase(StrPrinters(i)), "COLOR") Then
ActivePrinter = StrPrinters(i)
GoTo PrintDoc
End If
Next i
MsgBox "No color printer available"
Else
MsgBox "No printers found"
End If
Exit Sub
PrintDoc:
'MsgBox ActivePrinter
ActiveDocument.PrintOut
ActivePrinter = sPrinter
End Sub
 
B

BruceM

Thanks so much for the suggestions. I have to admit I don't fully
understand the AvailablePrinters code, but I used it anyhow, in combination
with your code, and was able to accomplish what I needed.
I wanted to generate a message box if the default printer varies from the
StrPrinters selection that includes the word "Color" (actually, "Color
Laser" in my case, and I removed UCase), but I found that ActivePrinter
includes the location (HP Color Laser on ABC6:) while StrPrinters does not
(HP Color Laser), so I did some text manipulation to remove " on..." from
the printer name before comparing it to the selected StrPrinters(i). If
they are the same, the color printer is the default, and there is no message
box; otherwise the user is advised of the printer that will be used, and is
told the default will be reset after printing.
Thanks again, and thanks also to the other who contributed to this thread.
I opted for the choice that avoided hard coding the printer name.
 

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