BeforeClose Event [Excel 2003 VBA Language Reference]

Occurs before the workbook closes. If the workbook has been changed, this event occurs before the user is asked to save changes.

Private Sub Workbook_BeforeClose(CancelAs Boolean)

CancelFalse when the event occurs. If the event procedure sets this argument to True, the close operation stops and the workbook is left open.

Example

This example always saves the workbook if it's been changed.

Private Sub Workbook_BeforeClose(Cancel as Boolean)
    If Me.Saved = False Then Me.Save
End Sub

Applies to | Workbook Object

See Also | Deactivate Event | WorkbookBeforeClose Event