Passing Argument to Excel Macro

You are not following the suggested method at the top.

The first macro works because it doesn’t have parameters so you can simply call the macro name.

The second macro would need to be amended to “Proc(”“newline””,1)"

This may answer Frank’s question as well.

RD

Apparently there’s a bug when sending parameters with Execute Macro activity that causes the macro to not function properly (VBA methods like Copy and Insert don’t work). The development team is aware of the bug and is presumably working on it.

2 Likes

Have they mentioned anything about macros executing twice in error? That is my current issue. I am able to pass parameters fine and the macro runs but the Execute Macro activity runs through the macro for a second time once the first run finishes then moves on to the next activity. All my test project consists of is an Excel application scope, Execute Macro then a Message box activity which was testing to see if UiPath would wait for the macro to complete before moving on.

Hi @code_monkey ,

They didn’t say anything about macros executing twice. Can you provide an example to see if the behavior can be reproduced? I see you created a topic for this (Execute Macro Activity Runs Twice), so maybe you should post it there.

Yes. Looks like that is a bug. Passing parameters to the Excel macro as we do now is more like a hack. It will be proper implemented and launched in about two weeks.

4 Likes

Problem Statement:
While working on excel automation sometimes we are asked to use existing VBA macros created by the business users and those VBA macros asks for input parameters at the time of execution.

Limitation:
In Execute Macro activity there is no option to pass input parameters as an argument to the macro or getting the output of the macro into a variable.

Please have this functionality integrated in Execute Macro activity.

Yes. It’s been proposed already.

workaround:
ex:

“Proc(”“Hello”",8)"

Considering Macro name is Proc and is accepting a string variable and integer variable.

Step 1
Create Macro that accepts parameter like below
Sub MyNewMacro(str1 As String)

MsgBox "Hello " + str1

End Sub

Step2
Call this macro using Execute Macro activity as shown below

image

Hi,

I also having a problem passing arguments in Macro.

image

Excel Macro…
Sub Marin(strMessage as String)
MsgBox strMessage
End Sub

every time I run it, it throws an error…
Can someone enlighten me :slight_smile:
Thanks!

Try logging the value first so you can see exactly what the macro is executing. You may need to use four quotes instead due to the number of quotes required.

I already try and found a solution on this “Marin(""" + msgbox + “”")(put a single quote on first after double quote and last before double quote) but I’m having a trouble now passing 2 arguments. The single quote is not working…
Once I figure again the solution I will post it here…
But if you already encounter this please help.
Thanks :slight_smile:

1 Like

Hi Frank_Mennink, did you find any solutions now how to execute macro passing two or more arguments? When I try passing 1 arguments it’s working but when I try t pass 2 o more it gives me an error.

I’m also trying to use Execute Macro Activity and trying to pass parameter of DateTime type. How do U achive that?

hi,

Please follow below tutorial

Thanks,
Karthik.