Error Handling - Get current Code Module Line

kswint

New Member
Joined
Aug 26, 2014
Messages
1
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
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
I'm not aware of any way to do exactly what you are asking. What you could do is set a string variable to different values at different locations in the code, then you can tell approximately where the error was.
 
Upvote 0

Forum statistics

Threads
1,226,588
Messages
6,191,888
Members
453,684
Latest member
Gretchenhines

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