Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Error Handling in VBA
Message
General information
Forum:
Microsoft Office
Category:
Other
Miscellaneous
Thread ID:
00840115
Message ID:
00840853
Views:
23
>I'm used to the fox and try am trying to write something decent in Excel with VBA. I'm desperate to find a way to replace my 15 year old default errorhandling (that I copied myself from someone who 15 years ago already had written it 15 years before).
>
>Any untrapped error goes to that routine and lets me close my application gracefully. I add a message to my users "wishing them a very good day too", which I must say is received with mixed feelings at times.
>
>I get the feeling that in VBA, there is nowhere I can call such an errorhanlder via the on error handler. And if I want to get the same kind of error handling, I would have to write errorhandling in each ean every procedure/sub and function.
>
>Please tell me I've overloooked something.
>
>Kind regards,
>
>Marc

My simple error handling in Access VBA looks rather like this:

Public Sub MySub
'various dims
On Error Goto errline
'lots of code

endline:
Exit Sub
errline:
Select Case Err.Number
Case 6666 'some anticipated error
' do something or other
Resume next
Case Else
Call ErrorHandle(Err.Number, Err.Description, _
"user-friendly text indicating the sub that had the error")
Resume endline
End Select
End Sub

ErrorHandle would be your favorite generic error handler, perhaps slightly modified. Mine doesn't do much more than put up a messagebox.

I know you aren't using Access, but there is a more substantial error handler in Chapter 14 of the Access 2002 Desktop Developer's Handbook by Litwin, Getz, and Gunderloy. I wouldn't be surprised if Sybex publishes a more general MS Office book, maybe written by some of the same people, with similar material on error handling.

I haven't worked in VFP in a while, so I'm forgetting the differences.
Previous
Reply
Map
View

Click here to load this message in the networking platform