Hello,
I have a workbook that allows users to pull information from various websites that use different log ins and update rather frequently. I am not the primary user of the book, though I am the only one that knows VBA to help troubleshoot if there is an error. As a result, I built a variation of the below to help notify me when someone runs the macro and encounters an error. The only errors that occur happen when the websites I pull from have been updated and the code I wrote is now outdated.
This code works perfectly and helps identify the error, though the macro is so long I don't know where the error has occurred. Is there any way to store the current code module line in a variable so that when an error occurs I can identify on what line number in the macro it occurred?
I know an alternative would be to use a collection of True/False if/then statements on my original workbook code to tell me how far I am through the Macro but I would love to try it this way if possible.
Public errstring
-----------------------------------
Sub errtest()
Dim x As Shape
On Error GoTo projectcall
x = 5
On Error GoTo 0
Exit Sub
projectcall:
errstring = Err.Number & ":" & Err.Description
'''''''?'''''''''errrow = thisworkbook.vbproject.vbcomponent("Module1").codemodule. (whatever will get me the line)
project
End Sub
-------------------------------------------
Sub project()
Dim outapp As Object
Dim outmail As Object
Set outapp = CreateObject("Outlook.Application")
Set outmail = outapp.CreateItem(0)
On Error Resume Next
With outmail
.To = myemail
.CC = ""
.BCC = ""
.Subject = "QMU Input Tool - Data Collection Error"
.Body = "Hello," & vbNewLine & _
"There was an error while executing the Data Collection macro for the QMU Tool." & _
"The error information can be found below." & vbNewLine & vbNewLine & _
errstring & vbNewLine & vbNewLine & "Please contact support if you have any questions." _
& vbNewLine & "Thank you!" & vbNewLine & "QMU Admin"
.Send
End With
On Error GoTo 0
End Sub
Thanks!
-Kswint
I have a workbook that allows users to pull information from various websites that use different log ins and update rather frequently. I am not the primary user of the book, though I am the only one that knows VBA to help troubleshoot if there is an error. As a result, I built a variation of the below to help notify me when someone runs the macro and encounters an error. The only errors that occur happen when the websites I pull from have been updated and the code I wrote is now outdated.
This code works perfectly and helps identify the error, though the macro is so long I don't know where the error has occurred. Is there any way to store the current code module line in a variable so that when an error occurs I can identify on what line number in the macro it occurred?
I know an alternative would be to use a collection of True/False if/then statements on my original workbook code to tell me how far I am through the Macro but I would love to try it this way if possible.
Public errstring
-----------------------------------
Sub errtest()
Dim x As Shape
On Error GoTo projectcall
x = 5
On Error GoTo 0
Exit Sub
projectcall:
errstring = Err.Number & ":" & Err.Description
'''''''?'''''''''errrow = thisworkbook.vbproject.vbcomponent("Module1").codemodule. (whatever will get me the line)
project
End Sub
-------------------------------------------
Sub project()
Dim outapp As Object
Dim outmail As Object
Set outapp = CreateObject("Outlook.Application")
Set outmail = outapp.CreateItem(0)
On Error Resume Next
With outmail
.To = myemail
.CC = ""
.BCC = ""
.Subject = "QMU Input Tool - Data Collection Error"
.Body = "Hello," & vbNewLine & _
"There was an error while executing the Data Collection macro for the QMU Tool." & _
"The error information can be found below." & vbNewLine & vbNewLine & _
errstring & vbNewLine & vbNewLine & "Please contact support if you have any questions." _
& vbNewLine & "Thank you!" & vbNewLine & "QMU Admin"
.Send
End With
On Error GoTo 0
End Sub
Thanks!
-Kswint