VBA Code To Set Printer Back To Default Printer

45 Views Asked by At

So recently I had to add some code to a legacy but 100% still production Excel Project to where it will print the workbook or just the page to PDF. I basically borrowed the code from the existing Print_Page and Print_Shipper (The Workbook) subroutines and then changed it to do this.

'set the active printer to Microsoft PDF printer using the function
   Application.ActivePrinter = FindPrinter("Microsoft Print to PDF")

So this works beautifully but in the same Excel session, if they want to go back to Print Page Or Printer Shipper (to printer), it is still going to PDF.

So after the Print PDF Subroutines run, how can I set it back to default printer with VBA? Everyone has different printer names and I don't let Windows set default but they do have a default set. Need to be able to pull what the "default" is and have it set back to it.

1

There are 1 best solutions below

1
taller On

Pls try.

Sub demo()
    Dim sPrinter As String
    sPrinter = Application.ActivePrinter
    Application.ActivePrinter = FindPrinter("Microsoft Print to PDF")
    ' Your code
    '...
    'Restore printer setting
    Application.ActivePrinter = sPrinter
End Sub