Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2005

Tip: Looking for answers? Try searching our database.

Help checking for printers in Word VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
spotvader@yahoo.com - 04 Jan 2005 14:10 GMT
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
Jonathan West - 04 Jan 2005 14:55 GMT
Hi spotvader

The following article includes code that lists all the available printers.
With this, you can compare the property value with the available printers.

Getting names of available printers
http://word.mvps.org/FAQs/MacrosVBA/AvailablePrinters.htm

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

>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
[quoted text clipped - 40 lines]
> ActivePrinter = sMyActivePrinter
> End Sub
spotvader - 04 Jan 2005 15:53 GMT
Jonathan,
Thanks so much... helped me finally put an end to this issue.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.