WorkbookBeforeClose Event [Excel 2003 VBA Language Reference]

Occurs immediately before any open workbook closes.

Private Subobject**_WorkbookBeforeClose(ByValWbAs Workbook**, ByValCancelAs Boolean)

object An object of type Application declared with events in a class module. For more information, see Using Events with the Application Object .

Wb The workbook that's being closed.

CancelFalse when the event occurs. If the event procedure sets this argument to True, the workbook doesn't close when the procedure is finished.

Example

This example prompts the user for a yes or no response before closing any workbook.

Private Sub App_WorkbookBeforeClose(ByVal Wb as Workbook, _
        Cancel as Boolean)
    a = MsgBox("Do you really want to close the workbook?", _
        vbYesNo)
    If a = vbNo Then Cancel = True
End Sub

Applies to | Application Object

See Also | BeforeClose Event