Error-Checking Sub Routines
A few things about this program need to be brought to your attention. The first thing to notice is the On Error Goto [Label] statement. This executes only if there is an error, but in this case, an error is intentionally triggered, as the comment indicates. Notice that the statement directs the program to the ErrorHandler label, where the error is handled by finding the error properties for the MsgBox. The second thing to notice is that the For..Each construct, which has been covered, loops through the Errors collection, which in this case only has one error, to find the error. The With statement, nested within the For..Each loop, is a great way to examine, read, or change object properties. The following example ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access