Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. 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.

Displaying the Print Dialog Box in a Macro

Written by Allen Wyatt (last updated June 5, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


2

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:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10321) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Displaying the Print Dialog Box in a Macro.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Develop Macros in Their Own Workbook

If you develop macros and edit them quite a bit, you may be running the risk of causing problems with the macros or with ...

Discover More

Quick Recall of Table Formats

Got a table that you use over and over again? One way you can make quick work of such repetition is to save the table in ...

Discover More

Accessing the Dirty Flag

When creating macros, you might want to know if a user has made changes in the document or not. Here's how to figure that ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Pulling Apart Characters in a Long String

You can easily use formulas to pull apart text stored in a cell. For instance, if you need to pull individual characters ...

Discover More

Updating Automatically when Opening Under Macro Control

If your workbook contains links, you are normally given the opportunity to update those links when you open the workbook. ...

Discover More

Copying Worksheet Code Automatically

When creating a workbook to be used by others, you may want any worksheets they add to the workbook to contain some ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 5 + 3?

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.


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.