Passing Arguments with Excel Run Macro

Discuss RoboTask here
Post Reply
twolsey
Posts: 2
Joined: Wed Jan 05, 2022 7:16 am

Passing Arguments with Excel Run Macro

Post by twolsey »

Hello

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

thanks
Tony
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Passing Arguments with Excel Run Macro

Post 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
Oleg Yershov
Kathrin_N
Posts: 1
Joined: Fri Nov 12, 2021 3:18 pm

Re: Passing Arguments with Excel Run Macro

Post 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
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Passing Arguments with Excel Run Macro

Post 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!!!""'"

Oleg Yershov
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Passing Arguments with Excel Run Macro

Post by Oleg »

To use some cell value as argument of macro use such expression
book1.xlsm!'MyMacro evaluate("C4")'
Oleg Yershov
Post Reply