Help checking for printers in Word VBA

S

spotvader

I have a macro that was written to extract a printer name from a custom
document property embedded in a Word file and set the printer to print
to based on that name. All of that is working just fine... my problem
comes when the printer named in the custom document property does not
exist on the current machine. Whenever this happens, I would like to
simply use the default printer on the current machine instead. I'm not
really sure how to check if a particular printer exists or not. Can
anyone help? My code is listed below... feel free to offer any
suggestions on the current working stuff too as I am a C# programmer
and the syntax here is foreign to me.

--------------------------------------------------------

Sub SubPrint()

Dim sMyActivePrinter As String
Dim iMyCopies As Integer

Selection.Collapse

sMyActivePrinter = ActivePrinter
iMyCopies = 1

For Each prop In ActiveDocument.CustomDocumentProperties
proptest = prop.Name
If proptest = "PrintCopies" Then
iMyCopies = prop.Value
End If
If proptest = "Printer" Then
ActivePrinter = prop.Value
End If
Next prop

Application.PrintOut FileName:="", _
Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=iMyCopies, _
Pages:="", PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, _
PrintToFile:=False, PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0

ActivePrinter = sMyActivePrinter
End Sub
 

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