Returning Errors from Functions

It is common programming practice to have functions return True if they executed without problem, and False if there was some irregularity. However, this makes it impossible, or at least difficult, to return any other information from the function. VBA's Variant data type comes to the rescue. One of this data type's abilities is to hold different types of data. Thus, a type Variant can hold a number that is just a number (to be specific, that is considered to be subtype Numeric) or it can hold a number that is subtype vbError. You use the CVErr function to convert a Variant to a subtype error, then use the IsError function to determine whether a Variant is subtype vbError. This technique permits a function to return ...

Get Office® XP Development with VBA now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.