Printer selection in Excel macro

Ask a question

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.
Jean-François Pillou

CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Learn more about the CCM team

Related