View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Paul Martin Paul Martin is offline
external usenet poster
 
Posts: 114
Default On Error, Capturing current module and actual line of code

Thanks for your suggestions Patrick, Frank & Tom.

I think passing the procedure name as a string parameter sounds like a
good idea. I thought there might be an application variable I could
use, but hard-coding the name (though not preferable) will do the
trick.

I'd prefer not to use line numbering, but if I go down that path, Erl
sounds like the solution. I find it odd that a search for Erl in the
VBA Help only returns Err. Erl stands for Err line?

Thanks again

Paul Martin
Melbourne, Australia


"Tom Ogilvy" wrote in message ...
Just to add:

From a previous post by Stephen Bullen:

If you number your lines, the Erl function will give the number of the
line:

Sub Test()

On Error Goto Err_Handler

1: For i = 10 To 0 Step -1
2: Debug.Print 1/i
3: Next

Exit Sub

Err_Handler:

Debug.Print "Error in line " & Erl

End Sub

I wrote a routine some time ago to automatically add line numbers to all
my code, prior to shipping it, but it's not what I'd call release-quality
<g

Regards

Stephen Bullen
Microsoft MVP - Excel
http://www.BMSLTD.ie

--
Regards,
Tom Ogilvy

"Paul Martin" wrote in message
om...
Hi all

I have written some code that captures date/time, err.Number,
err.Description, ActiveWorkbook.Name, etc and appends it to an
errorlog.txt file.

Is there some way that I can capture the actual code module and line
of code where the error occurred and write this to the file?

I'm looking at the following, but can't quite get what I'm after:
Application.VBE.VBProjects(1).VBComponents

Any help appreciated.

Paul Martin
Melbourne, Australia