Link to home
Start Free TrialLog in
Avatar of BrainStorm
BrainStorm

asked on

Set a printer as the default printer

How is it possible to set (by code and not using a common dialog) a printer as the default printer?
ASKER CERTIFIED SOLUTION
Avatar of GeoffKell
GeoffKell

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ahmadpj
ahmadpj

This is the answer:
add a listbox and add this code:

Dim P As Printer
 For Each P In Printers
 List1.AddItem P.DeviceName
Next

'after that, the user cans select one of them, then:

Private Sub List1_Click()
 Dim P As Printer
 For Each P In Printers
   If P.DeviceName = List1.Text Then
      Set Printer = P
      Exit For
   End If
 Next

 'now selected printer is the default printer
 Printer.Print "MY TEXT"
 Printer.EndDoc
End Sub
what is the "Printer" object... how do i reference it?