Workbook.BeforeClose event (Excel)
Occurs before the workbook closes. If the workbook has been changed, this event occurs before the user is asked to save changes.
expression A variable that represents a Workbook object.
|Cancel||Required||Boolean||False when the event occurs. If the event procedure sets this argument to True, the close operation stops and the workbook is left open.|
This example always saves the workbook if it has been changed.
Private Sub Workbook_BeforeClose(Cancel as Boolean) If Me.Saved = False Then Me.Save End Sub
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.