Error handlnig

sassriverrat

Well-known Member
Joined
Oct 4, 2018
Messages
655
I have this piece of error coding I've written. Userform18, when called upon, gives some info on how to further handle the error. Because I have hundreds of pieces of "error coding" (each one of them is idential but has a different ### assigned in the "with error codes [xxx]" piece, is it possible to get that error code to show up in userform18 or not because userform18 is a whole different part of the workbook? My idea here is to have a cmd button in userform18 that a person will click and it will auto email (with a pre-specified email and such) the error codes.... and hopefully a screenshot.

I'd also LOVE to have a piece of coding for Userform18 (another CMD button) that would take a screenshot of the coding that error'd for me to work with. Thanks!




Code:
'Error Clearing CodeExit Sub
Helper:
    resp = MsgBox("We're sorry to see you've encountered an error." & vbCrLf & vbCrLf & "To proceed, we recommend you contact the Developer " & _
    "with error codes [1057] and " & "[" & Err.Number & "-" & Err.Description & "]." & vbCrLf & vbCrLf & "To attempt to patch your problem at least " & _
    "temporarily, we recommend you click [Yes] to see help directions. Would you like to continue?", vbYesNoCancel, name)
        If resp = vbYes Then
            UserForm18.Show
            'MsgBox ("Success")
        ElseIf resp = vbNo Then
            Exit Sub
        ElseIf resp = vbCancel Then
            Exit Sub
        End If
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I have this piece of error coding I've written. Userform18, when called upon, gives some info on how to further handle the error. Because I have hundreds of pieces of "error coding" (each one of them is idential but has a different ### assigned in the "with error codes [xxx]" piece, is it possible to get that error code to show up in userform18 or not because userform18 is a whole different part of the workbook? My idea here is to have a cmd button in userform18 that a person will click and it will auto email (with a pre-specified email and such) the error codes.... and hopefully a screenshot.

I'd also LOVE to have a piece of coding for Userform18 (another CMD button) that would take a screenshot of the coding that error'd for me to work with. Thanks!




Code:
'Error Clearing CodeExit Sub
Helper:
    resp = MsgBox("We're sorry to see you've encountered an error." & vbCrLf & vbCrLf & "To proceed, we recommend you contact the Developer " & _
    "with error codes [1057] and " & "[" & Err.Number & "-" & Err.Description & "]." & vbCrLf & vbCrLf & "To attempt to patch your problem at least " & _
    "temporarily, we recommend you click [Yes] to see help directions. Would you like to continue?", vbYesNoCancel, name)
        If resp = vbYes Then
            UserForm18.Show
            'MsgBox ("Success")
        ElseIf resp = vbNo Then
            Exit Sub
        ElseIf resp = vbCancel Then
            Exit Sub
        End If
End Sub

There really isnt anything built in other than ERL. And ERL only works on lines containing a line number. This may accomplish what you need..

Code:
Public CurrentRoutine
Sub Error1_Test()
    CurrentRoutine = "Error1_Test"
    On Error GoTo ErrorHandler
    x = 1 / 0
Exit Sub
ErrorHandler:
    ErrorHandler Err.Number, Err.Description
End Sub
Sub Error2_Test()
    CurrentRoutine = "Error2_Test"
    On Error GoTo ErrorHandler
    x = ThisWorkbook * 3
Exit Sub
ErrorHandler:
    ErrorHandler Err.Number, Err.Description
End Sub
Function ErrorHandler(errNum, errDesc)
    Select Case errNum
        Case Else
            MsgBox "Code: " & Err.Number & vbCrLf & "Desc: " & Err.Description & vbCrLf, vbCritical + vbOKOnly, "An error has occurrend within " & CurrentRoutine
    End Select
End Function
 
Last edited:
Upvote 0
Interesting piece there....so how exactly would you recommend I add this function into my error code? Thoughts just being that I can add a call of the function or do I need the whole function? (I’ve got over a thousand subs...)
 
Upvote 0
Interesting piece there....so how exactly would you recommend I add this function into my error code? Thoughts just being that I can add a call of the function or do I need the whole function? (I’ve got over a thousand subs...)

If you have over 1000 subs, it is very likely that you have a large amount of redundant coding. I would imagine a large amount of that looks very similar and should probably be converted into functions. This is jsut a guess though. But that one function I have provided can handle ALL errorhandling from ALL subs and functions.
 
Upvote 0
to answer- yes- there is most definitely some redundant coding....there's certainly a lot of man-hours in it but it runs like a standalone program versus excel which is kind of cool!

Thank you
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top