|
-
May 16th, 2007, 06:27 AM
#1
Thread Starter
Addicted Member
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
Last edited by Mitch_s_s; May 16th, 2007 at 05:23 PM.
-
May 16th, 2007, 06:46 AM
#2
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
Use [code] source code here[/code] tags when you post source code.
My Articles
-
May 16th, 2007, 04:46 PM
#3
Thread Starter
Addicted Member
Re: Error Handling - Excel VBA
-
May 16th, 2007, 04:47 PM
#4
Thread Starter
Addicted Member
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!
-
May 16th, 2007, 05:06 PM
#5
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.
-
May 16th, 2007, 05:08 PM
#6
Thread Starter
Addicted Member
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
-
May 16th, 2007, 05:12 PM
#7
Re: Error Handling - Excel VBA
 Originally Posted by Mitch_s_s
does this add anything to processing time?
Not noticeably.
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.
-
May 16th, 2007, 05:13 PM
#8
Thread Starter
Addicted Member
Re: Error Handling - Excel VBA
hmm interesting,
it's just an excel add in then, that writes to the vbproject?
-
May 16th, 2007, 05:20 PM
#9
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.
-
May 16th, 2007, 05:22 PM
#10
Thread Starter
Addicted Member
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|