Passing Argument to Excel Macro

Do we need this? Since we have an workaround?

I have the below as macro code to test argument passing

Sub max(a As Long, b As Long)
MsgBox a & " " & b
If a > b Then
Sheets(“Sheet1”).Range(“A1”).Value = a
Else
Sheets(“Sheet1”).Range(“A1”).Value = b
End If
End Sub

This is in my execute Macro: “max(7,8)”

Nothing happens when I run the execute. Any ideas?

1 Like

Try “max(”“10"”,““15"”)”

Thanks for the reply. I have tried that, but that doesn’t work.

Hello everyone,

From what I’ve done and researched up until now, I saw that after creating a macro with parameters, UiPath is not running the macro anymore, or the modifications are not saved(which makes no sense). Is there some kind of bug? I mention the fact that i’m not receiving any kind of error.

my example:
//ading a new line

Sub newLine()

Dim value As Integer
value = int1
With ThisWorkbook.Worksheets(“Sheet1”)
Sheets(“Sheet1”).Range(“A” & CStr(1)).Select
ActiveCell.EntireRow.Insert shift:=xlDown
End With

End Sub

in execute macro i have “newLine”
=>working


Sub newLine(int1 As Integer)

Dim value As Integer
value = int1
With ThisWorkbook.Worksheets(“Sheet1”)
Sheets(“Sheet1”).Range(“A” & CStr(int1)).Select
ActiveCell.EntireRow.Insert shift:=xlDown
End With

End Sub

in execute macro i have “newLine(1)”
=>not working

Is this some kind of bug? Am I doing something wrong?
Here is the file macro_newLine.zip (14.7 KB)

1 Like

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:

2 Likes

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.