CallByName

Calls a method, or reads or writes a property, on an object — looked up by name at run time.

Syntax: CallByName( object , procname , calltype [ , args … ] )

object
required Object. The object whose member is to be invoked.
procname
required String. The name of the method or property to invoke on object.
calltype
required A VbCallType value indicating the kind of member: vbMethod, vbGet, vbLet, or vbSet.
args
optional The arguments to pass to the method, Property Get, Property Let, or Property Set.

The return value is a Variant containing whatever the call returned. For methods that return nothing, or for property assignments, the result is Empty.

Example

These three calls drive a control by name. The first sets its MousePointer property to the crosshair cursor, the second reads the same property back out, and the third invokes the Move method to reposition the control.

CallByName Text1, "MousePointer", vbLet, vbCrosshair
Result = CallByName(Text1, "MousePointer", vbGet)
CallByName Text1, "Move", vbMethod, 100, 100

See Also

License: CC-BY-4.0 Code license: MIT Attribution: VBA-Docs