ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error handler that does not end macro (https://www.excelbanter.com/excel-programming/370767-error-handler-does-not-end-macro.html)

Arne Hegefors

Error handler that does not end macro
 
I have an error handler that I use extensively. However most of the times I
just want to be able to inform the user of the error and then move on.
Sometime I save info on errors too. However they way that my error handler
works now is that it terminates the program when an error is being detected.
Please help me modify it so that it €śtolerates€ť mistakes and just warns the
user of the error.

My code is:

Public Sub mainProgram()
€¦..
On Error GoTo Handler
Exit Sub

Handler:

Select Case Err.Number
Case 600
Msgbox(€śError type 102€ť)
Case 601
Msgbox(€śfatal error!)
€¦€¦€¦
Case Else
End Select
End Sub

And in a sub somewhere in the code e.g. :
If x 10 then
Msgbox(€śWrong!€ť)
Err.raise 601
End if

As you can see if error occurs the error handler is called and when the code
for current error is finished the macro ends. Instead I want to call the
handler, do whatever it is I want to do for a certain error but then continue
in the sub where I left with the error. Please help me out! Thank you very
much in advance!


Tom Ogilvy

Error handler that does not end macro
 
Handler:

Select Case Err.Number
Case 600
Msgbox(€śError type 102€ť)
Case 601
Msgbox(€śfatal error!)
€¦€¦€¦
Case Else
End Select
Resume Next
End Sub

Or specify where you want it to resume.

--
Regards,
Tom Ogilvy



"Arne Hegefors" wrote:

I have an error handler that I use extensively. However most of the times I
just want to be able to inform the user of the error and then move on.
Sometime I save info on errors too. However they way that my error handler
works now is that it terminates the program when an error is being detected.
Please help me modify it so that it €śtolerates€ť mistakes and just warns the
user of the error.

My code is:

Public Sub mainProgram()
€¦..
On Error GoTo Handler
Exit Sub

Handler:

Select Case Err.Number
Case 600
Msgbox(€śError type 102€ť)
Case 601
Msgbox(€śfatal error!)
€¦€¦€¦
Case Else
End Select
End Sub

And in a sub somewhere in the code e.g. :
If x 10 then
Msgbox(€śWrong!€ť)
Err.raise 601
End if

As you can see if error occurs the error handler is called and when the code
for current error is finished the macro ends. Instead I want to call the
handler, do whatever it is I want to do for a certain error but then continue
in the sub where I left with the error. Please help me out! Thank you very
much in advance!



All times are GMT +1. The time now is 12:32 PM.

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