Run Macro Office

Runs a macro defined in an Office application opened by the IBM RPA Studio.

Command availability: IBM RPA SaaS and IBM RPA on premises

Script syntax

IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.

officeMacro --macro(String) --officeapplication(OfficeApplication)


  • To use this command, open an Office file with the Open Office file (officeOpen) command.

  • Microsoft™ Office 2010 or higher is required.

  • Ensure that the architecture (bitness) of your Office apps, IBM RPA, and your operating system match. For example, if you are using a 64-bit operating system, IBM RPA and Office must be 64-bit too.

To use this command, you must enable macros in Excel. The Following procedure shows you how to enable macros:

  1. Open Excel.
  2. Click the File tab.
  3. Click Options.
  4. Click Trust Center.
  5. Click the Trust Center Settings button.
  6. Go to Macro Settings and select Enable VBA macros (not recommended; potentially dangerous code can run).
  7. Click Ok and close the application.
  • Enabling this option can make your machine vulnerable to malicious code. Ensure that you only run safe macros with IBM RPA.
  • Ensure that the VBA project that contains the macro is not password encrypted.

Input parameters

The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.

Designer mode label Script mode name Required Accepted variable types Description
Macro macro Required Text Macro to be executed on the Office file.
Office Application officeapplication Required Office Application Variable that stores the Office Application instance.


The following code block demonstrates the use of the Run macro Office command.

defVar --name ID --type Numeric
defVar --name officeApplication --type OfficeApplication
// Download the following file to run this command.
officeOpen --path "Sample file" --type "Excel" --keepvisibleofficeApplication=officeapplication ID=processid
officeMacro --macro "Range(\"C1\").Value = WorksheetFunction.Sum(Range(\"A1:B1\"))\r\n" --officeapplication ${officeApplication}
// The macro adds 1+2 from the A1 and B1 cells, saving the result in C1.
delay --timeout 00:00:30
// Waits 30 seconds to close Excel.
officeClose --officeapplication ${officeApplication}
// When looking at the opened Excel file, you should see the following result:
// |A1|B1|C1|
// |1 |2 |3 |.


  • The command works only with .xlsm files.
  • The command cannot run Macros that are inside a password-encrypted VBA project.