Printer selection in Excel macro

February 2017


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.

Related


Published by aakai1056. Latest update on November 8, 2012 at 04:04 PM by Jeff.
This document, titled "Printer selection in Excel macro," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).