The print dialog box is a window that allows you to select various options for printing your workbook. You can access the print dialog box by clicking the File tab, then click Print, or by pressing the Ctrl+P keys on your keyboard. In the print dialog box, you'll see a number of options that you can select to customize your print job.
To display the print dialog box in a macro, you'll need to use the Application.Dialogs(xlDialogPrint).Show
method. The xlDialogPrint
constant represents the index number for the Print dialog box in the Application.Dialogs
collection. By using this method, you can control whether the dialog box is displayed modally or modelessly.
If you want the macro to continue running while the print dialog box is displayed, you'll need to set the Show
method's Modal
argument to False
. If you want the macro to stop running until the user closes the print dialog box, you'll need to set the Modal
argument to True
. The default value for this argument is True
, so if you omit it, the print dialog box will be displayed modally.
Example: Displaying the Print Dialog Box Modelessly
Sub PrintMacro()
' Display the print dialog box modelessly.
Application.Dialogs(xlDialogPrint).Show False
End Sub