I want to use CallByName to call different functions on an object.
The functions can all have a different number of arguments.
CallByName is defined as:
Function CallByName(Object As Object, ProcName As String, CallType As VbCallType, Args() As Variant)

But when i pass a variant array, an error is generated (Argument not optional)
It works when I pass the arguments one by one, but i need it to work with a variable number of parameters.

The following is a sample to reproduce the problem.

VB Code:
  1. Private Sub Command1_Click()
  2. Dim params() As Variant
  3. Dim Result As Variant
  4.     ReDim params(1)
  5.     params(0) = "Test"
  6.     params(1) = "test"
  7.     Result = CallByName(Me, "MyFunction", VbMethod, "Test", "Test") '<-- This will work
  8.     Result = CallByName(Me, "MyFunction", VbMethod, params) '<-- The produces an error
  9. End Sub
  10.  
  11.  
  12. Public Function MyFunction(ByVal a As String, ByVal b As String) As String
  13.     MyFunction = a & b
  14. End Function