-
Dear VB users,
Writing a VBA application, I do have to select a printer on the network.
Is this possible in VBA
In VB I am using:
Dim MyPrinter as Printer
For each MyPrinter in Printers
msgbox MyPrinter.DeviceName
next
Please can someone give me VBA source and/or information wich references I do have to choose.
Nice greetings,
Michelle.
-
In both Word and Excel VBA you can use the ActivePrinter property of the Application object.
Code:
ActivePrinter = "HP LaserJet 4 local on LPT1:"
-
Thanks Joacim Andersson.
I am searching for selecting a printer on a network.
Is there someone who can help me???
Nice regards,
Michelle.
-
Here michelle try this.
dim thisprinter as printer
for each thisprinter in printers
if thisprinter.devicename = " " then
set printer = thisprinter
exit for
next
But also make sure you have the commondialog box on your form.
-
Thanks jeffro,
The source you send to me is known for me. I don't understand what you mean with
"But also make sure you have the commondialog box on your form."
I placed a "print form" on my form but the source is stumbling over the Dim line.
Please can you be more clear with your last sentence?
Nice regards,
Michelle
-
Printers on network
If you know the printers name and server etc (UNC address) then you can use the api.
eg printer is \\matt_loc1\mjgprin0012
Code:
Declare Function AddPrinterConnection Lib "winspool.drv" Alias "AddPrinterConnectionA" (ByVal pName As String) As Long
Public Function AddPrinter(ByVal sName$) As Boolean
Dim lRes As Long
lRes = AddPrinterConnection(UCase(sName))
End Function
There is also a DeletePrinterConnection call.
-
Well if you are using a menu you should also use a commondialogbox. What a commondialog box does is it can bring up the print dialog box and then from there you can choose to print your form. You can find the commondialog box in the components in the project menu in vb. Just click on it and then apply the component. If have any more questions just email me at [email protected].
Sorry about being unclear earlier!!