Macro_BeforeClose event...Possible??

S

SuperJas

Hi

Would it be possible to catch when a user prematurely ends a macro by 'Ctrl-Break'? I would like to reset the Statusbar (ie set it to False) before quitting the macro. I guess what I'm looking for is an event similar to the Workbook_BeforeClose..

Many thanks for any suggestions

SuperJas.
 
R

Rob van Gelder

Take a look at Application.EnableCancelKey


--
Rob van Gelder - http://www.vangelder.co.nz/excel


SuperJas said:
Hi,

Would it be possible to catch when a user prematurely ends a macro by
'Ctrl-Break'? I would like to reset the Statusbar (ie set it to False)
before quitting the macro. I guess what I'm looking for is an event similar
to the Workbook_BeforeClose...
 
C

Chip Pearson

You can use the Application.EnableCancelKey property to control
how VBA responds to Ctrl+Break. For example

Application.EnableCancelKey = xlErrorHandler
On Error GoTo ErrHandler:
'
' your code here
'
Exit Sub
ErrHandler:
If Err.Number = 18 Then
MsgBox "You pressed break"
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



SuperJas said:
Hi,

Would it be possible to catch when a user prematurely ends a
macro by 'Ctrl-Break'? I would like to reset the Statusbar (ie
set it to False) before quitting the macro. I guess what I'm
looking for is an event similar to the Workbook_BeforeClose...
 
Top