VBA: how to test for object equality (whether two variables reference the same object) VBA: how to test for object equality (whether two variables reference the same object) vba vba

VBA: how to test for object equality (whether two variables reference the same object)


I'm guessing that's telling me to override the '=' operator to test if all the fields of the two objects have the same value.

No, it tells you the objects don't have a default property which would have been called otherwise, and the returned results compared.

You test reference equality with Is

If myObject Is yourObject Then 


You need to serialize the objects somehow and then compare attribute by attribute values. The "is" operator is as dumb as it gets, it only matches if another object is the same instance assigned to the compared variable.I suggest using a jsonStringify library. I adapted one for my DexTools.xlam open source project https://github.com/dexterial/Dextools/tree/master/Main starting from the Parsing JSON in Excel VBA post. It has much more added features since I added quite a few other excel objects serialization/hashing options and it is made using the vba test driven development that DexTools incorporates. It is still work in progress so dont expect miracles