Create an Excel.xlsx and run a macro

Good evening,
My tasks.robot is creating an Excel file during its execution, let’s call it Excel99.xlsx :
I want to re-design the header (apply header filters, change color etc) and replace text of entries inside of this new Excel99.xlsx.
To do this I’m looking to run an Excel macro or the corresponding VBS script.
My question is: how can i run a macro that is stored on another MacroExcel.xlsm file on the same folder of Excel99.xlsx ? Alternatively how can i directly run the VBS script so that it applies to Excel99.xlsx?

If i should just resort to python let me know, i’m open to any ideas.
Thank you!

Best regards,
Vasco

Hi @JimmyYung

to run the Excel macro you could use RPA.Excel.Application library and keyword Run Macro:

To run the VBS you could try to use built-in Run Process with shell=True config:

It should work because it uses Python’s subprocess library.

2 Likes

Good afternoon @RoboHeart
Thank you very much for the detailed answer.
First point: i’m trying to run a macro saved in another Excel File, because of how Excel Stores local macros (in a local unique “personal” spreadsheet on your Windows) i’m unable to run the macro i want on a new and fresh Excel created during Cloud execution.

Second point: Your second solution seems to be perfect, executing the VBS script of the macro targeting the fresh excel.

I’m currently resolving the issue and formatting the fresh Excel using aux python Library ( xlrd ) that does what i require :slight_smile:

Thank you very much for your help! All the best, stay safe and calm
Vasco

2 Likes

Sounds great. :slight_smile:

In case you are using rpa-framework, RPA.Excel.Files is also using the xlrd library.

1 Like