It is an old question, I know, but for the sake of correctness:
VBA's CallByName does not accept a string as
"The name of the object on which the function will be executed."
In some places the MSDN example is distorted to a plainly wrong one.
It has to be the object per si.
So, instead of:
Call CallByName("itm", PAN_Source, VbGet)
Do that:
Call CallByName(itm, "NameMethodThatUsesString_PAN_Source" , VbGet, PAN_Source)
PAN_Source has to be supplied at the optional Args().
As a bonus, if it returns something as a Function (vbMethod), receive it with a Variant:
auxVar = CallByName (itm, "NameMethodThatUsesString_PAN_Source" , VbGet, PAN_Source)
I use it mostly to iterate over some Collections to SortIt() or retrieve values -
or both - through Property Get or Set, in a Sorting algorithm, for example:
...
If IsMissing(CallByNameArg0) Then
If VarType(CallByName(this, SortPropertyName, VbGet)) = vbObject Then
Set thisValue = CallByName(this, SortPropertyName, VbGet)
Else
thisValue = CallByName(this, SortPropertyName, VbGet)
End If
Else
If VarType(CallByName(this, SortPropertyName, VbGet)) = vbObject Then
Set thisValue = CallByName(this, SortPropertyName, VbGet, CallByNameArg0)
Else
thisValue = CallByName(this, SortPropertyName, VbGet, CallByNameArg0)
End If
End If
...
Where this
is the Object that we want to CallBack and CallByNameArg0
is a Variant (to allow IsMissing(CallByNameArg0 )
)
And in case that someone try to CallByName against Standard Module, it will not function; instead, try Application.Run