Terry,
I would be surprised if Excel can work like that, because if code is
executing (which must be the case if the user presses ^BREAK), your code
cannot run.
I suppose that's why your have the .EnableCancelKey property.
You can achieve your goal if you set it to = xlErrorHandler ?
See the help for an example.
Alan,
Whilst I would not necessarily advise closing/quitting in such a suitable,
you can decide what to do:
Private Sub CommandButton1_Click()
Dim i As Long
Dim j As Long
Application.EnableCancelKey = xlErrorHandler
On Error GoTo Handler
For i = 1 To 100000
For j = 1 To 10000
Debug.Print "Value=: " & i * j
Next
DoEvents
Next
Exit Sub
Handler:
'Either an error or the code has been stopped
MsgBox "You are in the handler." & vbNewLine & "Exiting routine."
'Do what you want
End Sub
NickHK
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.