Why is VBA's VarType function saying this COM object is a string? (Object is instance of COM version of .NET's System.Object class.) Is it a bug?
See the question and my original answer on StackOverflowIf you open the typeLib C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.tlb
with OleView for example, and navigate to the _Object
interface (not the first _Object one, the dispinterface, but the second one) you'll see this:
So, the .NET method Object.ToString()
is declared to COM/Automation clients as
[id(00000000), propget, custom(54FC8F55-38DE-4703-9C4E-250351302B1C, 1)]
HRESULT ToString([out, retval] BSTR* pRetVal);
Which means it's seen to COM clients that understand this "syntactic sugar" (VB/VBA/VBScript/JScript/.NET, etc.) as a Property (propget + out + retval) named ToString
that returns a String (BSTR).
Now, id(0)
means it's the default property, because 0 represents DISPID_VALUE, a special well-known id.
And lastly, VB/VBA VarType's documentation states this:
If an object has a default property, VarType(object) returns the type of the object's default property.
(which I always found a pretty strange design decision...)