Printing with VBA

Asator

Board Regular
Joined
Apr 5, 2010
Messages
186
I know there's a few different ways to store the default printer as a string, but is there a way I can then prompt the user from a popup with a list of printers, and set their selection as the default printer?

application.dialogs(xldialogprintersetup).show only returns true when they select a printer. I can use wscript.network to list all printers and set a default printer, but I don't think there's a way to have it return the default printer (in UNC format).

TL;DR - I want to store the current default printer, prompt the user with a list of installed printers, set their selection as default, then reset the printer to their pre-macro default when done.

Is this possible?
 
No, but the process launches and the xlapp.activeprinter does return the current default printer.
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
That's a good point. I was hoping I could call that speicific dialog box to set the printer, but I guess that's not going to work.

Any ideas on how I could accomplish this? Is there a way I can generate a popup window with a drop down menu whose values are populated by an array? I could enumerate all the printers from wscript.network to create that array...
 
Upvote 0
Just tried it in my test code:
Code:
Sub setprinter()
Dim xlApp As Object
Dim prConfig As Object
On Error GoTo fail
Set xlApp = CreateObject("excel.application")
Set prConfig = CreateObject("wscript.network")
    prOld = Left(xlApp.ActivePrinter, InStr(xlApp.ActivePrinter, " on Ne") - 1)
    xlApp.Visible = True
    Do Until prResponse = True
        prResponse = xlApp.Dialogs(9).Show 'xlDialogPrinterSetup
    Loop
    xlApp.Visible = False
    prNew = Left(xlApp.ActivePrinter, InStr(xlApp.ActivePrinter, " on Ne") - 1)

Same error...
 
Upvote 0
Interdasting. That seems to have fixed it.

When excel opens a new instance, is the ActivePrinter always set to to the default printer (until changed)?
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,270
Members
452,902
Latest member
Knuddeluff

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