Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Displaying the Print Dialog Box in a Macro.
by Allen Wyatt
(last updated November 1, 2014)
Before printing anything in Excel, it is not unusual to display the Print dialog box. This allows you to make changes to how the print job will be handled by the printer driver.
If you are creating a macro that is used to print information from your worksheets, you may want to display the Print dialog box programmatically. The user can then choose to print, directly from within your macro.
To add this capability, simply include the following macro line:
bTemp = Application.Dialogs(xlDialogPrint).Show
The Show method results in the Print dialog box being displayed. When this code line is finished, bTemp will be either True or False. If True, it means that the user clicked on OK in the dialog box, thereby printing something. If False, then the user either clicked on Cancel or the Close button to close the dialog box without printing.
You might wonder if this approach will work in Excel 2013 seeing as the program now uses what Redmond refers to as "Backstage view" to intiate printing. (Just press Ctrl+P and you can see the printing options in Backstage view.) Fortunately, it does. Excel 2013 dutifully displays the Print dialog box as it appeared in earlier versions of the program, bypassing completely the need for what you see in Backstage view.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10321) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Displaying the Print Dialog Box in a Macro.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
When developing a macro, it is often necessary to step through the various code lines so you can see what is happening on ...Discover More
It is not uncommon to set variables in a macro based on other values, such as time or date. You could also set variables ...Discover More
When you use a macro to process data you always run the risk of making that data unusable by Excel. This is especially ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.