HELP: error handling in VBA
Here's how I trap errors.
Sub ErrorTesing()
On Error GoTo ErrStop
' enter vba code here like - email code
'Note: you do not have to put Exit Sub
'the error free code passes through the ErrStop:
'& ends on End Sub
ErrStop:
If Err Then MsgBox ("Error Occurred " & Err)
End Sub
If an error is detected in your code it will be displayed in a MsgBox
"Error Occurred xxx"
where xxx is the error number
HTH,
--
Data Hog
"sam" wrote:
Hi All,
Why do we use "On error resume next" shouldnt we be resolving those errors.
For eg: if we are sending important email notifications through excel VBA
which affect management decisions, shouldnt we be avoiding to user "On error
resume next"? IF for some reason there is an error and an email is not sent
it might affect a lot of things.
My concern is: how do we handle error is this situations? is there a better
way to handle errors, rather than using "On error resume next" statement?
Thanks in advance.
|