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?
BrainStormAsked:
Who is Participating?
 
GeoffKellConnect With a Mentor Commented:
0
 
ahmadpjCommented:
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
0
 
Mike JohnsonBusiness Inteligence DeveloperCommented:
what is the "Printer" object... how do i reference it?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.