If MsgBox("Are you sure?", vbYesNo + vbQuestion, "Close") = vbNo Then Private Sub Workbook_BeforeClose(Cancel As Boolean) The Cancel parameter can be set to True to stop the workbook from closing. It happens before any checks are done to see if the workbook needs to be saved. Workbook_BeforeClose() fires when the user tries to close the workbook. Private Sub Workbook_Open()Įnd Sub Workbook_BeforeClose(Cancel as Boolean) If you get the Security Warning after opening a workbook, this event fires after clicking “Enable Content”. The Workbook_Open() event fires when a workbook is opened.
The following are a small, but useful sample of Excel Events that you could run macros from.
Information about how to create a clickable Button or Shape can be found here: Add a Button and Assign a Macro in Excel. This is much quicker for end-users than opening lists of macros or digging through macro code in the VB Editor. It’s often useful to have a control on the worksheet that a user can click to run a macro, like a Button control or a Shape.