View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
John Green[_3_] John Green[_3_] is offline
external usenet poster
 
Posts: 49
Default Trapping Excel Close Event

Bob,

There is no Application Close or BeforeClose event. However, you can trap the Before_Close event for a workbook that results from
the closure of the application. You can do this for all open workbooks by trapping application events. Try placing the following
code in the ThisWorkbook module of a workbook such as Personal.xls:

Option Explicit

Dim WithEvents xlApp As Excel.Application

Private Sub Workbook_Open()
Set xlApp = Excel.Application
End Sub

Private Sub xlApp_WorkbookBeforeClose(ByVal Wb As Workbook, Cancel As Boolean)
'Do stuff
End Sub

"Do stuff" will be executed when any workbook is closed and can include setting Cancel = True to prevent the closure of the workbook
and the application.

--

John Green - Excel MVP
Sydney
Australia


"Bob J." wrote in message ...
Can anyone help with trapping the application.quit event
that is triggered by clicking on the close (X) box in the
upper right title bar or when the user performs a
File_Exit command and there is no Save Box genereated?
Workbook_close and _Deactivate do not seem to work.

Thanks

Bob