Hi Matt,
Matt said:
What is the 'scope' of On Error Resume Next?
Is it for a sub, for the next line after the statement only, for a
module, or for a workbook/project?
If more than one of these, how does one specify the different ones?
Thanks
Matt
There is one more thing worth mentioning here. Yes, error handling set in a
routine will be reset when that routine has finished executing. However,
any procedures called *by that routine* that do not have their own error
handling will inherit the error handling of the calling routine. This can
cause unexpected results if you aren't prepared for it.
For example:
Sub Demo()
On Error Resume Next
SubA
SubB
On Error Goto 0
End Sub
Sub SubA()
Dim rng As Range
rng = Range("A1")
End Sub
Sub SubB()
Dim l As Long
l = CLng("ABC")
End Sub
Even though runtime errors are generated by both SubA and SubB, no error
message will be displayed. That is because error handling rolls "uphill" -
since SubA has no error handling, the error is raised back up the call stack
to the Demo subroutine, which then handles the error by Resume Next and
continues on to call SubB. Since SubB has no error handling defined, the
same thing happens when it encounters a runtime error. This behavior
extends all the way through the call stack, so if you have SubA that calls
SubB, which in turn calls SubC, and SubB and SubC have no error handling
defined, the error handler in SubA would catch any errors from SubA, SubB,
or SubC.
Just thought I'd mention this behavior in case you weren't aware of it.
--
Regards,
Jake Marx
MS MVP - Excel
www.longhead.com
[please keep replies in the newsgroup - email address unmonitored]