I'm working on user-proofing a VBA app in Excel and I realized I'm constantly rewriting a lot of the same code to create specific error messages that are fed strings of info for the user to be able to tell me when they inevitably call me to say they're getting errors.
I want to create something like this to simply call on each error and pass the particulars:
Sub GenericError(ErrNum As Long, ErrDesc As String, sequence As String, errtype As String)
'In case of error, returns actual error code and calls for abort; if no abort then can debug
Dim msgstrng As String
msgstring = sequence & " error " & errtype _
& vbLrCf & "Error code " & ErrNum & " - " & ErrDesc
MsgBox msgstring, , sequence & " Error!"
cont = Abort_Check()
On Error GoTo 0
End Sub
Then ideally I could use something like
On Error Call GenericError(Err.Number, Err.Description, "Startup Sequence", "File Not Found")
'code that opens a file....
On Error goto 0
It seems like On Error only works with goto or resume; there are a bunch of modules that would need this in a lot of subs so writing basically this in a bunch of different GoTo blocks is annoying. Is there a solution for me to use an error to call a sub like this?