Folks-
I'm in the business of creating and maintaining bandaids, as such I distribute code to people all over my company. I've created some code that catchs errors and emails me the error information. I'd like to know if I can add the Name (and Line??) of the Macro passing the error information so that I can more easiliy identify the problem. I'd also like to know which errors are non-fatal so that I don't have to worry about those. Also, I can't use any add-ins or plug-ins due to the security policys of the company.
[vba]
Private OLApp As Object
Private OLNS As Object
Private Sub Run()
On Error GoTo Err
' <Code here>
Err:
Select Case Err.Number
Case 0
Resume Next
Case Else
Application.WindowState = xlNormal
Call EmailErr(Str$(Err) & ":" & Err.Description, vbInformation) 'would like to add macro name here
MsgBox "Macro Failed! Error information has been emailed to griffism."
GoTo Exits
End Select
Exits:
End Sub
Private Sub EmailErr(errName As String, errInfo As String) 'mName as string
Dim oMailItem As Object
Dim oRecipient As Object
Set OLApp = CreateObject("Outlook.Application")
Set OLNS = OLApp.GetNameSpace("MAPI")
OLNS.Logon , , True
Set oMailItem = OLApp.CreateItem(0)
Set oRecipient = oMailItem.Recipients.Add("edited by Admin")
oRecipient.Type = 1
With oMailItem
.Subject = "Macro Error"
.Body = "griffism- & vbNewLine & The error is: " & errName & " " & errInfo ' & " " & mName
.Send
End With
End Sub
[/vba]