Get Module line # for error trapping

  • Thread starter Thread starter Geof Wyght
  • Start date Start date
G

Geof Wyght

Hello everyone,
When I error trap, I write out the module name and
procedure name. I always wanted to drill down one more
layer and write out the line that was executing in the
procedure when the runtime error occured. I've looked at
lots of line-type properties of the VBE object, but can't
seem to find the one I've described. Am I out of luck?
Thanks.
Geof.
 
You can number all your lines (no colons):
and display the error line using erl:

Sub LookHere()
100 a=5
200 a=6
300 On Error GoTo ErrRtn
400 msgbox 5/0 'gives an error
500 exit sub
ErrRtn:
Msgbox "Error in line " & erl
End Sub
 
Hmmm... I had forgotten about line numbers. This means
that you have to number the lines. Perhaps one could just
number lines with a high potential to generate a runtime
error. Interesting...
Geof.
 
Here's a bizzare solution:
1) Export the VBA code to a cls file.
2) Import the cls file to an Access table with an
autonumber field.
3) Export the Access table to a text file of some sort.
4) Import the text file into an Excel module.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top