(un) a safe way to do this - if you're okay without using the option explicitly - this is ...
Not TypeName(myObj) = "Empty"
It also handles the case if the object was not declared. This is useful if you just want to comment on an ad to disable some behavior ...
Dim myObj as Object Not TypeName(myObj) = "Empty" '/ true, the object exists - TypeName is Object 'Dim myObj as Object Not TypeName(myObj) = "Empty" '/ false, the object has not been declared
This works because VBA will automatically create an undeclared variable as the type of Empty Variant. This eliminates the need for auxiliary logic to control behavior.
Cool Blue Oct 30 '16 at 3:10 2016-10-30 03:10
source share