View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_3_] Bob Phillips[_3_] is offline
external usenet poster
 
Posts: 2,420
Default OnError - what generated the error?

You have 3 pieces of information that you can use. The first two are
straight-forward, Err.Number and Err.Description. The third needs to have
line numbers added to utilise

Sub TestError()
Dim Somevar As Double

10 On Error GoTo TestError_Error

20 Somevar = 7
30 Somevar = Somevar + 12
40 Somevar = Somevar / 0

TestError_Exit:
50 Exit Sub

TestError_Error:
60 MsgBox "Error: " & vbNewLine & _
" number: " & Err.Number & vbNewLine & _
" description: " & Err.Description & vbNewLine & _
" line number: " & Erl
70 Resume TestError_Exit

End Sub

Personally, I have never found Erl necessary, the error description usually
is enough. You could also add a procedure name constant and display that
value as well.

If you get MZTools, a free VBE utility from
http://www.mztools.com/v3/download.aspx , this has a function to
automatically add and remove line numbers.

--
__________________________________
HTH

Bob

"Robeyx via OfficeKB.com" <u43777@uwe wrote in message
news:887367d1bc4fe@uwe...
A simple problem. If an OnError routine is invoked, how can you tell which
instruction caused the error?

There must be an easy way, but I can't find it. Single-stepping is not
what
I mean, I just want there to be a field somewhere that tells me the
previous
instruction executed.

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200808/1