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
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