Execute Macro Detail

I have seen the documentation about executing Excel Macro but it’s not very clear exactly how to do it and I have some questions.

  1. the documentation mentions about sample file but not sure where I could find them ( sample_macro.zip)
  2. Why are there two parameters one is Path and the other is Macro file path. If Macro file path is the VBS file then what happens to the macro on the xlsm file? How do I execute the macro on the excel file?
  3. How do I pass a parameter to either of the macro? I can see that in VBS sample you have "Set Book = xlApp.Workbooks.Open(WScript.Arguments(0)) " what is WScript.Arguments(0) ?

Hello Rommel,

Thank you for your feedback. Here’s how you can proceed:

  1. We appreciate you bringing this to our attention. We’ll review the download link for the sample file to ensure it’s accessible.

  2. Studio Pro Macro Support: Studio Pro supports macros using .vbs files. The “Path” field expects an Excel file, which doesn’t necessarily have to be an .xlsm type; it can be an .xlsx file as well. This file will be used to load the .vbs macro logic. The “Macro file path” field is for the .vbs file containing the macro script. Studio Pro requires the macro to be in a .vbs format rather than embedded directly in the Excel file because it executes VBScript files.

  3. Passing Parameters to .vbs Script: You can pass parameters to the .vbs script using the WScript.Arguments array. For instance, WScript.Arguments(0) can be the path of the Excel file, and WScript.Arguments(1) can be another parameter you need to pass to your macro. In Studio Pro, you can send these parameters using the “Input Arguments” field.

Please feel free to reach out if you have more questions or need further assistance!

Best regards,

1 Like

Thank you for your reply.
so does it mean that ultimately the macro that will be running is the one on the VBS (Macro File Path) and if the excel file has a macro in it, it won’t be executed?

My use case is, I have an excel file which I need to manipulate using another Macro enable excel file and generate a new formatted excel file. Not sure VBS is robust enough to manipulate the data I need but I can explore that. Does it mean, the Path can be the excel file input data, then I use VBS to format the input data and spit out another formatted excel file?

I will have to test passing another parameter to the VBS. still learning about the input arguments.

Hi @Rommel,

Yes, the macro logic that will be executed is defined in the .vbs file.

Additionally, you can use .vbs files to format Excel files. For instance, you can apply bold formatting to specific rows, set a background color for specific columns, or change the font size of individual cells. These are just a few examples of the formatting options available through .vbs files. Moreover, you can also process data, read matrix data, and perform operations as needed using .vbs scripts, similar to .vba macros.

Do you know a way to call a function/sub on the excel vba from the vbs? I noticed that if i put a vba on the opening of workbook that it gets executed as well.

I tried the input parameter but it’s giving me an error.
image

Set Book = xlApp.Workbooks.Open(WScript.Arguments(1))

error: Wrong number of arguments or invalid property assignment

can i please get help, I can’t get the Execute Macro to work in a workflow, it keeps giving me this error

I have tried everything. It only work when I start at the Execute Macro itself.

It seems to be working when i pass an empty array

but can’t get it to work when i pass one item of string
either of this doesn’t work:
[“text”]
“test”

hey @Rommel

There is an example of a bot with .vbs macro used and an array specified (with a values inside) in the Input arguments

Execute_macro.zip (299.0 KB)

Also, you can find a few other examples in the ‘How-to’ articles here:
https://docs.electroneek.com/page/how-tos-convert#how-to-convert-a-xls-file-to-a-xlsx-file-using-the-execute-macro-activity
https://docs.electroneek.com/page/how-tos-miscellaneous#how-to-copy-values-from-one-column-to-another-using-the-execute-macro-activity