Is there any way to check if variable was originally declared as Variant
data type?
Consider the following example:
Public Sub mainMethod()
Dim a As Variant
Dim b As String
a = "a"
b = "b"
Debug.Print "a: " & VBA.TypeName(a) & " | " & VBA.VarType(a)
Debug.Print "b: " & VBA.TypeName(b) & " | " & VBA.VarType(b)
End Sub
Output is:
a: String | 8
b: String | 8
After assigning a text to the variable declared as Variant
, both VBA built-in functions to check the type of variable (VarType
and TypeName
) treats it as variable of String
type.
The effect is that variables a
and b
are treated the same way by those functions mentioned above, although originally they were declared with different data types.
I know how to check it by parsing method body with VBE
functions, but it is not acceptable in this case.