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.

‘INSERT CODE HERE

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!

Submeg

IT

Posted by:submeg

Musician, Writer and Inspirer. I discuss the projects I am working on, the services I provide and my general thoughts.

6 replies on “Excel VBA Tips: Selecting the Default Printer in VBA

  1. —————————
    Microsoft Visual Basic for Applications
    —————————
    Compile error:

    Variable not defined
    —————————
    Error on AtcivePrint = ………

    Like

  2. Does this work for the default printer, or the last printer used in excel?
    I’m having trouble printing to a default printer via VBA after printing to a different printer. It seems like Activeprinter is not the default, but the last printer used through excel…

    Like

    1. When you mean the last used printer, had you printed anything earlier in the day or was it printed the day before, prior to turning the computer on for the day?

      Like

      1. As it acts just like my quick print button. It prints to the last printer used, or default on start up.

        Like

Tell me what you think!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s