Written by Allen Wyatt (last updated February 5, 2025)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and 2021
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 and later versions seeing as the program now uses what Redmond refers to as "Backstage view" to initiate printing. (Just press Ctrl+P and you can see the printing options in Backstage view.) Fortunately, it does. Later versions of Excel dutifully display the Print dialog box as it appeared in earlier versions of the program, bypassing completely the need for what you see in Backstage view.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10321) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and 2021. 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!
The security features built into Excel allow you to digitally sign your macros so that users can rest assured that they ...
Discover MoreIf you need to limit the cells that are accessible by the user of a worksheet, VBA can come to the rescue. This doesn't ...
Discover MoreIf you keep on-going data in a worksheet, some of your data�"over time�"may need to be deleted. If you have an ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2021-06-08 11:26:49
J. Woolley
@Joan Koskela
See Application.GetSaveAsFilename Method:
https://docs.microsoft.com/en-us/office/vba/api/excel.application.getsaveasfilename
Then see Workbook.SaveAs Method:
https://docs.microsoft.com/en-us/office/vba/api/excel.workbook.saveas
For example:
vName = Application.GetSaveAsFilename(...)
On Error Resume Next
ActiveWorkbook.SaveAs Filename:=vName
bSuccess = (Err.Number = 0)
On Error GoTo 0
If bSuccess Then MsgBox "ActiveWorkbook is now " & vName
Also, see XlBuiltInDialog Enumeration:
https://docs.microsoft.com/en-us/office/vba/api/excel.xlbuiltindialog
2021-06-07 09:32:11
Joan Koskela
Would this work to display the Save As dialog box (xlDialogSaveAs)? I've tried recording a Save As in a macro but when the macro runs it always just saves the document but I need to give it a new unique name each time. I'd save it as a template but it's a work-in-progress and I'd just like it to open the Save As dialog box whenever I or someone else opens it so no one saves the document with data in it.
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments