Quick question on Error Trapping

D

Darrin Henshaw

So far in my short VBA programming experience, I have not done much in
the way of Error Trapping(I know that is a BAD thing). Lately, I've been
reading a few VBA books to learn more, and realized I need to code Error
Trapping.

In Excel 2002 Power Programming With VBA, by John Walkenbach, he
mentions that after using: On Error Resume Next, you need to restore
normal error handling with "On Error GoTo 0". My question is if the
current workbook is closed, without using the "On Error GoTo 0", is
error handling returned to normal? Thanks.
 
C

Chip Pearson

I think you misunderstand what John wrote regarding error
handling. To wit, it is NOT required that you use "On Error Goto
0" after an "On Error Resume Next". If you have an "On Error
Goto somewhere", then you DO need to use Resume or Resume Next
(or Exit Sub or End Sub) in your error handling block to restore
VBA's normal error handling.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
V

Vasant Nanavati

It depends on what you mean by "current workbook." Do you mean the active
workbook, or the workbook containing the code?

Of course, once your macro is exited, error handling returns to normal.
 
D

Darrin Henshaw

Thanks Chip. In re-reading it, I understand how I interpreted it. I
thought it was like turning ScreenUpdating off, that in order for it to
work correctly, you need to turn it back on.
 
T

Tom Ogilvy

Error handling has local scope - so as soon as the procedure ends, any error
handling options are cleared.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top