VBA - CallByName won't accept variant arguments
I've spent a long time trying to figure out what was wrong with how I was using CallByName. I finally realized that its fourth argument (Args) will throw a type mismatch if the input is not either EXACTLY the same type as the input argument of what its calling or its hard-coded in.
(I don't even understand how, or why, it does this since
VarType(Variant/Integer) = VarType(Integer))
So I either need a way to make it accept variant inputs or convert variables from
Integer (or create a new variable) without a giant select case.
Edit: So my question wasn't clear so I'll explain it in more detail. I have a bunch of classes that I want to cycle through and call the
Let property on. My simplified setup is:
Function SetAll(TargetProperty as String, Value as Variant) For each ClassX in AllClasses CallByName ClassX, TargetProperty, vbLet, Value Next ClassX End function
The problem is
Value when it is initialized as
Variant. The only time I can get it to not throw a type mismatch exception is when I initialize
Value as the exact same type that the property wants, but I can't do that since the data types in the class vary.
Edit 2: I'm going to ask another question about the whole problem since no one seems to know much about
Edit 3: Here's a summary of what we have so far:
CallByName's fourth argument (Args) throws a type mismatch when trying to call the
Letproperty on a class.
This only happens when the value trying to be assigned is stored in a
Variantdata type. It works perfectly if the variable is initialized to the same type the
Letproperty is expecting OR if the value is hard-coded into the argument.
Letproperty works fine on its own. It accepts
Variantdata types just fine.
My question is: Is there a way to stop this exception? I'm creating another post about other possible solutions to my overall problem.