Set printer in VBA

jrisebo

Active Member
Joined
Mar 15, 2011
Messages
325
Office Version
  1. 365
Platform
  1. Windows
Here is some code that I use to print multiple sheets by pressing a button. I want it to change to a specific printer, called "PDFcreator" in my printer list. What can I add to do that? Thanks

Private Sub CommandButton1_Click()
'PRINT LRFD ATTACHED CALC'S WITH DB-SAE'S
'

'
Sheets("ATT INFO").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1
Sheets("ATT Service").Select
ActiveSheet.PageSetup.PrintArea = "$A$55:$F$137"
ActiveWindow.SelectedSheets.PrintOut Copies:=1
Sheets("ATT Strength").Select
ActiveSheet.PageSetup.PrintArea = "$A$56:$F$154"
ActiveWindow.SelectedSheets.PrintOut Copies:=1
Sheets("ATT Extreme").Select
ActiveSheet.PageSetup.PrintArea = "$A$56:$F$154"
ActiveWindow.SelectedSheets.PrintOut Copies:=1
Sheets("INPUT").Select
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Here's some code I used to allow user to change to Zebra printer. I then changed back to what they started from so they didn't have to [which is I capture the active default printer upfront]

Code:
    Set dlgSetPrinter = Application.Dialogs(xlDialogPrinterSetup)
    ' capture default active printer
    strPrinter = dlgSetPrinter.Application.ActivePrinter
    ' prompt change to Zebra printer; capture name of Zebra printer
    dlgSetPrinter.Show
    strZebraPrinter = Application.ActivePrinter
 
Upvote 0
zebra printer is the name of a printer in your printer list?
 
Upvote 0
That's exactly what I was going to ask.

What about if the printer is shared? Do you need the network path, how does that work?
 
Upvote 0
I posted as shown, and it brings up a printer list box that I can pick which one to use. Great Success! Thanks:biggrin:
 
Upvote 0
It looks like Access after 2002 had this great object. I wonder if there's anything like it in Excel. I already checked, it doesn't have exactly the same thing.

Set Application.Printer = Application.Printers("Name")
 
Upvote 0
You could also specify the ActivePrinter argument when using PrintOut.
 
Upvote 0

Forum statistics

Threads
1,224,544
Messages
6,179,430
Members
452,915
Latest member
hannnahheileen

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