Excel VBA Tips: Selecting the Default Printer in VBA


Excel VBA Tips: Selecting the Default Printer in VBA

I had created a document that is to be printed by multiple people in different locations. However, when pressing the print button that I created on the worksheet, I needed to ensure that the default printer for each location was selected. This can be done with the following code:

Sub DefaultPrint()

activePrint = Application.ActivePrinter
‘This sets the variable as the active printer that is currently selected in excel.


Application.ActivePrinter = activePrint
‘This ensures that the code has not changed the default printer

ActiveWindow.SelectedSheets.PrintOut Copies:=1
‘The print command. There are multiple ways to do this

MsgBox “This has been sent to your active printer: ” & Application.ActivePrinter
‘Displays a message to the user so they know which printer it has been sent to.

End Sub

The above code will ensure that when printing, it is sent to the default printer for any user that prints from the worksheet.

Come check out the directory for the rest of my excel tips!