Printer name and tray selection with vba code

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
I have been on the web for a while now looking for solutions to my problems. I came a bit closer yet I am stacked trying to complete the next steps:


Code:
Private Declare Function CreateIC Lib "gdi32" Alias "CreateICA" _
                        (ByVal lpDriverName As String, ByVal lpDeviceName As String, _
                        ByVal lpOutput As String, ByVal lpInitData As Long) As Long


Public Function GetPDC(ByVal strPrinter As String) As Long
    GetPDC = CreateIC("WINSPOOL", strPrinter, vbNullString, 0&)
End Function




Sub Look_For_Printer()
   'printer_name = "Name found in the print setup drop down"
   printer_name = Application.ActivePrinter
   
   If GetPDC(printer_name) = 0 Then
      MsgBox "Printer name : " & Application.ActivePrinter & vbNewLine & _
                "Printer status : Not found on this computer", , ""
   End If


End Sub


Sub SwitchPrinter()
    If MsgBox("Active printer name is : " _
                    & Application.ActivePrinter & vbNewLine & _
                    "Will you change the active printer?", vbYesNo, "") = vbYes Then
        Application.Dialogs(xlDialogPrinterSetup).Show
    Else
       MsgBox ("The printer was not changed")
    End If
End Sub


Sub ChangeTrays()
     Application.SendKeys "%fu%e{TAB}{DOWN}{DOWN}{TAB}m~{ESC}", True
    Application.SendKeys "%fu%e{TAB}{DOWN}{DOWN}{TAB}m~~", True
 End Sub


Now these are my requirements:
1. Display a msgbox alert with active or default printer name with an alert to ask user if there is a need for printer change.
2. If yes, then display the printer selection dialog box
3. Verify if the active printer has multiple trays or just a single one
4. If multiple, then ask user to select the required tray
5. Verify with msgbox alert if the selected printer is online, that is if it is connected to the pc.


Thanks in advance
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top