Number of Parameters specified does not match the expected number

I really don’t understand why I am getting this error.
I am using Invoke VBA activity against my Excel sheet, and I am sending an array parameter, but I am getting

Invoke VBA: Number of parameters specified does not match the expected number

this is weird because they DO match. In my UiPath, I have:

Assign: arrayRenameColumns (of string) = {“A”, “B”, “C”, “D”, “E”, “F”, “1”, “2”, “3”, “4”, “5”, “6”}

Invoke VBA Properties
CodeFilePath - “correct macro path”
EntryMethodName - “mySubName”
EntryMethodParameters - arrayRenameColumns

Note: arrayRenameColumns is declared as variable.

Now inside Macro file, I have

Sub mySubName(ByRef arrColumns() As String)
/* More VBA code in here*/
End Sub

The number of parameters are both 1 on both sides, and it is an array of string. Why am I getting this error?

Okay actually I figured it out and it is working now.

Instead of using ByRef, you have to use ParamArray keyword.
Also, instead of type String, you must use type Variant when using ParamArray keyword.

Before: Sub mySubName(ByRef arrColumns() As String)
After: Sub mySubName(ParamArray arrColumns() As Variant)
I hope this thread will one day help some other people with the same issue.


This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.