Error Handling - Excel VBA [RESOLVED]
What i want to be able to do is the following:
i want be able to extract the line of code that is running that cause the error
e.g if you had on line 32
average = 32/0
this statement would give you an error, is there anyway i could extract this line number.
What i then want to do is to display a message box saying
"Please contact your administrator quoting L32 and " & Err
where L32 is the line number, and Err is obviously the error number.
Thanks
Mitch
Re: Error Handling - Excel VBA
To get the Line numbers, you need to add the line numbers in the code. A search here would have just shown you what you have to use
Code:
Public Sub ErrorLineNumber()
On Error GoTo ErrHandler
1: Dim x As Integer
2: Dim y As Integer
3: x = 0
4: y = 10
5: Dim z As Integer
6: x = y / x
8: MsgBox "Succeeded"
9: MsgBox "Just another msgbox"
Exit Sub
ErrHandler:
MsgBox "Error Occured at Line Number " & Erl
End Sub
Re: Error Handling - Excel VBA
Re: Error Handling - Excel VBA
i removed the numbers!
so all my subs need their lines to be numbered?
no other way no?
thanks by the way!
Re: Error Handling - Excel VBA
You must number each line for it to work.. tho you can use an addin like MZTools (link in my signature) to automatically add them for you.
Re: Error Handling - Excel VBA
does this add anything to processing time?
bit of a pain doin that to my already created sub :(
might check out the add in
Re: Error Handling - Excel VBA
Quote:
Originally Posted by Mitch_s_s
does this add anything to processing time?
Not noticeably.
Quote:
bit of a pain doin that to my already created sub :(
might check out the add in
The addin will do it instantly, for the entire project if you like. ;)
Re: Error Handling - Excel VBA
hmm interesting,
it's just an excel add in then, that writes to the vbproject?
Re: Error Handling - Excel VBA
It a VBA (or VB) addin, which has lots of useful features.. when I first got it, it saved me about 25% of my coding effort. ;)
Re: Error Handling - Excel VBA
cheers man, might install it at home
tight security in work, so they may not allow me to install it there!
Thanks for this! :)