Ask a question »

Printer selection in Excel macro

August 2015


Issue


I have an Excel file (2007), in which I print sheets via 2 network printers.
  • I've written a macro to select thename printers, it works in my PC, but not necessarily for another one.
  • I want all users to have access to the printer of their choice via a macro, is it possible?

Solution


Try this:

Sub test() 
Dim DefaultPrinter As String, Imprimante1 As String, Imprimante2 As String 
'Stocke le nom de l'imprimante par défaut, pour la remettre en fin de module 
DefaultPrinter = Application.ActivePrinter 
'Printer #1 choice
Application.Dialogs(xlDialogPrinterSetup).Show 
Imprimante1 = Application.ActivePrinter 
'Printer #2 choice 
Application.Dialogs(xlDialogPrinterSetup).Show 
Imprimante2 = Application.ActivePrinter 
'Show names stored in variables 
MsgBox Printer1 
MsgBox Printer2 
'Reset default printer : 
Application.ActivePrinter = DefaultPrinter
End Sub



Thanks to pikaju for this tip.
For unlimited offline reading, you can download this article for free in PDF format:
Printer-selection-in-excel-macro.pdf

See also

In the same category

Published by aakai1056. - Latest update by Jeff
This document entitled « Printer selection in Excel macro » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.