Forum Discussion
heylookitsme
Jan 29, 2021Iron Contributor
Excel VBA Reference Line Where Error Occurs
I have searched the web over to find out how I can set my error handler to reference the line in the code that errors. I currently have it set so my error handler sends me an email with the details o...
heylookitsme
Jan 29, 2021Iron Contributor
HansVogelaarI appologize, Let me clarify. The attached pic shows Line reference data that VBA shows when working in each module. What I'm saying is there should be a way to reference this line when errors occur.
HansVogelaar
Jan 29, 2021MVP
Yes, I know, but that information is not exposed to the programmer when an error occurs.
There is an obscure function Erl that returns the line number of an error, but if you haven't actually added line numbers, Erl always returns 0.
The Err object doesn't provide line number information... 😞
- heylookitsmeJan 29, 2021Iron ContributorThat information is not exposed to the programmer when an error occurs.
It should be. That would provide a great way for programmers to get specific error details which would help them debug errors much faster. I see this having huge potential if it were available.- jlansteadFeb 14, 2023Copper Contributor
https://www.fmsinc.com/free/newtips/VBA/ErrorHandling/LineNumber.html
First, you must number the lines and then reference the line number that causes the error using ERL.
You can find an example in the link above.