Invoke VBA - error in parameters

Hello,
I am trying to run a VBA in an excel using parameters because they change in each excel file. My macro is:
Sub Macro1(ParamArray arrColumns() As Variant)

Worksheets("""+mes+""").Range(“A23:G”"+alcance+""").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.BorderAround ColorIndex:=1

End Sub

The error I get is:

can anyone help me please?

Hi

Welcome to uipath forum

Have a view on this thread for how to pass variable to a function in VBA using Invoke VBA activity

Cheers @liliana.novais

Hello,
Thanks for your reply, I still have the problem I followed that explanation. The sheet name is stored in an input argument and the range is also in a variable. And my macro does not run. If I hardcode it in my file it runs but if I use arguments it does not work

Is the variable declared in same way as in the above thread both with the activity and within the VBA code

Cheers @liliana.novais

Hi,
Generally speaking UiPath passes to VBA unnamed variables. As we see, you try to use named parameters in your VBA code. If you want your code to work you have two options:

  1. Change Macro1 parameter array (ParamArray arrColumns() As Variant) to named parameters, e.g., mes As String, alcance As String. Then use Worksheets(mes).Range("A23:G" & alcance).Select

OR

  1. Leave parameter as is, but use indexes in further code, e.g. Worksheets(arrColumns(0)).Range("A23:G" & arrColumns(1)).Select

Either way provide values in your activity (EntryMethodParameters input) , e.g., New String(){mes,alcance}. Order of parameters must be kept.

About VBA named parameters