Page 1 of 1

Passing Arguments with Excel Run Macro

Posted: Wed Jan 12, 2022 2:53 am
by twolsey
Hello

Is there a way with Excel Run Macro action to pass arguments to the macro?

thanks
Tony

Re: Passing Arguments with Excel Run Macro

Posted: Sun Jan 16, 2022 10:58 am
by Oleg
Excel application allows to run macro manually or by hot-key. But it does not allow to pass something to a macro.
We made the similar function.

However the object model of Excel application allows to pass up to 30 parameters to a macro.
Probably we need to improve this action

Re: Passing Arguments with Excel Run Macro

Posted: Wed Jan 26, 2022 2:53 pm
by Kathrin_N
Would this solve my problem, too? I want to process Excel Sheets automatically. When I open an Excel Sheet without Robotask everything works fine and the data update automatically. When I open the Sheet with Robotask the background processes do not start. It is a Excel Sheet with Power Query.

Regards Kathrin

Re: Passing Arguments with Excel Run Macro

Posted: Thu Oct 06, 2022 8:11 am
by Oleg
How to run macro with arguments

Suppose we have very simple macro in excel document

Code: Select all

Sub MyMacro(Amsg)
    MsgBox Amsg
End Sub
To run the macro use such expression:
book1.xlsm!'MyMacro "Hello Wold!!!"'
or
'MyMacro "Hello Wold!!!"'

Note that the entire macro expression must be enclosed in single quotes.
The macro function argument must be enclosed in double quotes.

Also look at simple example below. Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.
Also you can simply copy task text and paste it into the task list.

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|444033236
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task1040"
Hide=INTEGER|0
ID=INTEGER|-618855983
LogOnAsUser=INTEGER|1
Name=STRING|"EXCEL macro with arguments"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER

[Actions\Action1]
ActionID=STRING|"A_EXCEL_OPEN"
Enabled=INTEGER|-1
Name=STRING|"Excel Open Document"
Params=FOLDER

[Actions\Action1\Params]
filename=STRING|"C:\temp\Book1.xlsm"
hide=STRING|"0"
mode=STRING|"0"
tryconnect=STRING|"1"

[Actions\Action2]
ActionID=STRING|"A_EXCEL_RUNMACRO"
Enabled=INTEGER|-1
Name=STRING|"Excel run macro ""book1.xlsm!'MyMacro ""Hello Wold!!!""'"""
Params=FOLDER

[Actions\Action2\Params]
macroname=STRING|"book1.xlsm!'MyMacro ""Hello Wold!!!""'"


Re: Passing Arguments with Excel Run Macro

Posted: Thu Oct 06, 2022 8:17 am
by Oleg
To use some cell value as argument of macro use such expression
book1.xlsm!'MyMacro evaluate("C4")'