vba_monkey
Board Regular
- Joined
- Dec 18, 2013
- Messages
- 112
Hello,
I am trying to get excel to go to my error handler if Esc is pressed whilst the macro is running. This is what I have so far but when I press Esc, Excel goes to the error handler and breaks on the first line with error 'User interrupt occurred' instead of running through the code in the error handler:
Any ideas please?
I am trying to get excel to go to my error handler if Esc is pressed whilst the macro is running. This is what I have so far but when I press Esc, Excel goes to the error handler and breaks on the first line with error 'User interrupt occurred' instead of running through the code in the error handler:
Code:
On Error GoTo Error_Handler
Application.EnableCancelKey = xlErrorHandler
Error_Handler:
If Err = 18 Then
MsgBox "Macro exited...", vbExclamation, "Stopped!"
Else
Debug.Print "Line: " & Erl & " Desc: " & Err.Description
MsgBox "An error occurred, exiting macro...", vbCritical, "Error!"
End If
End Sub
Any ideas please?