Execute Excel macro with argument throws range does not exist error

So, here’s the code in the XSLM file, Module1:

Sub CloneTemplate(strName As String)
    'strName = "wubba"
    Sheets("EXAMPLE").Select
    Sheets("EXAMPLE").Copy After:=Sheets(Sheets.Count)
    Sheets("EXAMPLE (2)").Select
    Sheets("EXAMPLE (2)").Name = strName
End Sub

Here’s the activity in my XAML:
image

Here’s the error:
Source: Execute macro

Message: The range does not exist

Exception Type: ExcelException

UiPath.Excel.ExcelException: The range does not exist ---> System.Runtime.InteropServices.COMException: Cannot run the macro 'CloneTemplate("Alberts, Joseph")'. The macro may not be available in this workbook or all macros may be disabled.

Note that when first testing this, the macro did not have the parameter, strName was hardcoded, and the Execute Macro called, simply, “CloneTemplate”. THIS WORKED! As soon as I added the argument to the macro and tried to execute the macro using it, that’s when the fun began.

Most vexing. Really hoping someone can offer a suggestion.

Thanks.

ddk

Holy How Stupid is that, Batman? Discovered that you need to enclose the full macro name, with arguments, within SINGLE quotes!

So:
"CloneTemplate(""" + thatPerson + """)"
not good.

OTOH:
"'CloneTemplate(""" + thatPerson + """)'"
good.

First one is passed to Excel as CloneTemplate(“Gorgeous George”)
Second is passed to Excel as ‘CloneTemplate(“Gorgeous George”)’

ddk

2 Likes

Can you tell me why’s the error is still prompting?


This is my code.

Hope you can help me. Thanks

This is happening to me as well right now. I have followed the simplest of instructions but I still get the ERROR: Macro doesn’t exist or disabled.

This macro has no parameters yet. Can you tell me why?

This is how it looks like in VBA IDE:

image

Managed to make it work. Maybe just too sleepy to focus earlier. lol. cheers

Those single quotes did the job. Now I can continue.