Event handling in VBA

G

Gaston AGON

hello world !

cann anyone tell me if there is an event behind the clic on the
Close button (the red X-box) in the upper right corner of each
excel window and in the excel window itself ? and how to catch
those events from a VBA programcode ?

Hier is the problem I need to solve :

my application request normally the user to exit via an integreted button,
because of some housekeeping actions before terminate,
but the red X-buttons allow actually the user to bybass these actions !

How can I solve this?
Thanks in advance for any suggestions.
Gaston.
 
G

George Nicholson

but the red X-buttons allow actually the user to bybass these actions !
Here's one possible approach (air code):

(Workbook-level variable)
bolOKtoClose as boolean

WorkbookOpen:
bolOKtoClose = False

Your "integreted button"_Click (after houseKeeping)
bolOKtoClose = True

Workbook_BeforeClose
If bolOKtoClose = False Then
Cancel = True
MsgBox "Please use the 'integrated button' to close this workbook"
End if

The idea is that using your button is the only way to set bolOKtoClose to
True, and it has to be True for the Workbook to close.

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top