InvokeVBAXアクティビティでVBAへの引数の渡し方を教えて

こんばんは
UiPath Studio 2025.0.172STS Community editionのユーザーです。

1.やりたいこと

InvokeVBAXアクティビティで外部ファイルからExcelマクロを呼び出して実行したい。

2.悩んでいること

デバッグすると、InvokeVBAXアクティビティで下記のエラーが出ます。

System.Reflection.TargetParameterCountException: Number of parameters specified does not match the expected number. at Microsoft.Office.Interop.Excel._Application.Run(Object Macro, Object Arg1, Object Arg2, Object Arg3, Object Arg4, Object Arg5, Object Arg6, Object Arg7, Object Arg8, Object Arg9, Object Arg10, Object Arg11, Object Arg12, Object Arg13, Object Arg14, Object Arg15, Object Arg16, Object Arg17, Object Arg18, Object Arg19, Object Arg20, Object Arg21, Object Arg22, Object Arg23, Object Arg24, Object Arg25, Object Arg26, Object Arg27, Object Arg28, Object Arg29, Object Arg30)
at UiPath.Excel.WorkbookApplication.ExecuteMacro(String macroName, IEnumerable1 macroParameters) at UiPath.Excel.WorkbookApplication.InvokeVBA(String codeFilePath, String entryMethodName, IEnumerable1 entryMethodParams)
at UiPath.Excel.Activities.Business.InvokeVBAX.InvokeVBAInternal(IWorkbookQuickHandle handle, String codeFilePath, String entryMethodname, IList1 arguments) at UiPath.Excel.Activities.Business.InvokeVBAX.ExecuteDoWork(ActivityContext context, ExecuteVBADescriptor descriptor) at UiPath.Shared.Activities.BaseParentActivityWithDescriptor2.OnCompleted(NativeActivityContext context, ActivityInstance _)
at System.Activities.Runtime.CompletionCallbackWrapper.CompletionWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

@gorby,

Check if you have another variable with name “Excel”. If yes rename or delete it.

Also check if you are passing the Excel variable to correct property and the properties sequence not different like yesterday.

Hi, I resolved this issue on my own using two methods!

For your reference, here are the correct solutions I found.

  1. I had placed the macro file in \macro\macro_code.txt instead of the root directory, so I moved it to the root.

  2. The argument declaration in the first line of the macro was incorrect. Since I am not familiar with Excel macro notation, I comitted such a mistake.

Incorrect: Sub ApplyStripesToRows()

Correct: Sub ApplyStripesToRows(Sheetname As String, Range As String)

Cheers to your Lord Shiva and Parvati and appreciate your advice

1 Like

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