ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Centralised error handler (https://www.excelbanter.com/excel-programming/328719-centralised-error-handler.html)

[email protected]

Centralised error handler
 
Hello,

Maybe this looks kind a weird, because there are a lot of topics about
this isue.
Anyway I hope somone can give me a clear explanation if it is possible
(and how), or it isn't.
In most of the topics i saw questions about error handlers within error
handlers.
Or the topics are from 1997, so i think there is a lot different right
now.

I have round 8 procedures who will run with one button.
This is my errorhandler code:
Public Sub Errorhandler()
On Error GoTo handleCancel
Application.EnableCancelKey = xlErrorHandler

For X = 1 To 1000000 ' Do something 1,000,000 times (long!)
' do something here
Next X

handleCancel:
If Err = 18 Then
If MsgBox("Do you want to quit?", vbYesNo) = vbYes Then
GoTo Ending
Else
Resume
End If
End If
Ending:

Under Ending there normally is a code who protect my sheets again.
My question is can i make a procedure with this errorhanler, so this
handler will be active all the time when the macro is running??

I couldn't found somthing like that in other posts, or it was so
complex i don't get it anymore.



All times are GMT +1. The time now is 11:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com