Passing Argument to Excel Macro

We have Execute Macro activity, We can have the option where we can pass arguments to Excel Macro directly. I have seen the functionality in other RPA tool.

5 Likes

Is this being looked into?
when will this functionality be available?

Hi,

You can make a call to the macro as follows:

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

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

Thanks,
Yuga

9 Likes

@yuga that’s extremely helpful - how did you work that out?!

It’s the default macro syntax but with escaped quotations

Yes simple enough but I wouldn’t have guessed it :slight_smile:

adding it to documentation :wink:

2 Likes

@richarddenton: Struggled initially to get the syntax right.

help,

not it works

1 Like

Basically you should pass a string variable like that:
“change_sheet(”“” + sheet + “”“)”

In Excel I could pop up a messagebox showing the string. However, for unknown reasons I couldn’t select the specified sheet via VBA. It run through the VBA code without error message and without processing two commands (Stop/Worksheets.Select). But anyway you can select you sheet directly from UiPath (Select Range activity).

My code in VBA was the following:

Public Sub change_sheet(ByRef sheetName As String)
Stop
MsgBox sheetName
Worksheets(sheetName).Select
End Sub

I hope that helps!

3 Likes

hi,

I’ll try it :smiley:

it work

thx :smiley: :grin::blush:

Personally I always assign fairly complicated string concatenations to a variable and then log them. If something is wrong or goes wrong it’s then far easier to debug.

RD

1 Like

How could we get a value from Excel macro?

No one can give bad answer like this

Run Macro

Write value to Cell in Macro (If you can)

Read Cell

Write Cell - String.Empty

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