20 | 09 | 2017

Select Printer

When working on AutoCad, Office etc. You can use different options to select a printer. Below a routine is shown to create a userform to select a printer. To make it work create a Userform and add four controls. Like the screenshot below:


"Select printer form"

Add the code below to the userform.

Private Sub Form_Load()

   Dim x As Printer
   'Load the combo with all available printers
   For Each x In Printers
      Combo1.AddItem x.DeviceName
      If Printer.DeviceName = x.DeviceName Then 'Current default
         Combo1.Text = x.DeviceName
      End If
   'Set the number of copies to 1
   Combo2.ListIndex = 0
   'Preset the orientation radio buttons
   optOrientation(Printer.Orientation - 1).Value = True
End Sub
Private Sub Combo1_Click()
   Dim x As Printer
   For Each x In Printers
      If Combo1.List(Combo1.ListIndex) = x.DeviceName Then
         Debug.Print "User selected "; x.DeviceName
         Set Printer = x
      End If
End Sub
Private Sub Command1_Click()
   'If Portrait radio button selected, use vbPRORPortrait else use vbPRORLandscape
   Printer.Orientation = IIf(optOrientation(0).Value, vbPRORPortrait, vbPRORLandscape)
   'Set the number of copies
   Printer.Copies = Combo2.Text
   'Add code to send data to the printer
End Sub

Sign up now and upload your code to the website.

Help us to continue.....
Articles View Hits
Latest Articles