Cancel Excel Workbook Printing with the VBA BeforePrint Event
Question details
Prevent a workbook from printing when the user selects Cancel in a VBA confirmation dialog.

- Product
- Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- A workbook uses the Workbook_BeforePrint event to ask the user for confirmation before printing.
- Observed behavior
- Printing can continue when the procedure exits without setting the event's Cancel argument to True.
Open the workbook in desktop Excel and make sure macros are enabled for the file. The Workbook_BeforePrint event belongs to Excel, not Word; Word uses a different print event.
Set the BeforePrint Cancel Argument from the Dialog Result
Use this event procedure to cancel printing when the user clicks Cancel and allow it to continue when the user clicks OK.
In Excel, press Alt+F11 or select Developer > Visual Basic.
In the VBA editor's Project Explorer, expand your workbook project and double-click ThisWorkbook.
Add or update the procedure in ThisWorkbook: Private Sub Workbook_BeforePrint(Cancel As Boolean) Cancel = (MsgBox("Always 2 Copies and Sorted", vbOKCancel, "Caution") = vbCancel) End Sub
Save the file as an Excel Macro-Enabled Workbook (.xlsm), then choose File > Print. Click Cancel in the message box and verify that printing stops; repeat and click OK to allow printing.

Work with Spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for opening, editing, and printing spreadsheets. Its format compatibility makes moving everyday documents easier, but it does not fix Excel's VBA event behavior; test any macros before relying on them.

Frequently Asked Questions
Why does printing continue after I click Cancel?
Exiting the event procedure alone does not cancel printing. In ThisWorkbook, set the Workbook_BeforePrint event's Cancel argument to True when the dialog returns vbCancel.
Where should I put the Workbook_BeforePrint code?
In Excel, open Developer > Visual Basic, then double-click ThisWorkbook under your workbook project and add the event procedure there.
Why doesn't the confirmation dialog appear?
Check that the file is saved as .xlsm, macros are enabled, and the procedure is in ThisWorkbook. Also check whether events have been disabled; in the VBA editor's Immediate window, you can enter Application.EnableEvents = True.
Can I use Workbook_BeforePrint in Microsoft Word?
No. Workbook_BeforePrint is an Excel workbook event. Word uses a different application-level print event, DocumentBeforePrint, which also provides a Cancel argument.




