How do you use exception handling in visual basic?
How do you handle exc开发者_StackOverflow中文版eptions in visual basic?
VBA doesn't call it exception handling, rather it calls it error handling and it has a different syntax than what can be found in VB.Net or Java etc.
You need to research the On Error
statement, specifically the On Error Goto <LABEL>
where you can say that if any error occurs, then go to the specified label where you put your error handling code.
You can also tell the code to ignore errors by doing On Error Resume Next
, but this should normally only be used very sparingly for as few lines as possible and then needs to be followed by On Error Goto 0
to reset the error handling.
See these articles for more information:
Error Trapping with Visual Basic for Applications
Error Handling In VBA
精彩评论