Excel - Run macro
Declaration
<AMEXCEL ACTIVITY="run_macro" SOURCE="text" VISIBLE="YES/NO" DESTINATION="text" OVERWRITE="YES/NO" MACRO="text" CELLREF="text" WORKSHEET="text" />
Description
Runs an existing Excel macro, which is typically a set of instructions created by recording a sequence of keyboard and mouse actions using the Excel Macro Recorder. This activity requires an interactive logon session in order to function properly.
Practical usage
An Excel macro is an automated input sequence that is used to eliminate the need to repeat the steps of common tasks over and over. With Automate, Excel users can run existing macros any time with the simple touch of a button or automatically start the macro upon the occurrence of an event or condition, greatly speeding complicated spreadsheet work.
Parameters
Macro
Property | Type | Required | Default | Markup | Description |
---|---|---|---|---|---|
Source | Text | Yes | (Empty) | SOURCE="c:\temp\file.xlsx" | The path and file name of the Excel macro-enabled workbook (*.xlsm) that this activity should run. Click the folder icon to navigate to the file using an Open File dialog. |
Application is invisible | Yes/No | No | No | VISIBLE="NO" | If selected, specifies that the Excel window will not be displayed during runtime and all processing will occur in the background. This option should be disabled during task construction and debugging but can be selected for production. Disabled by default. |
Destination | Text | Yes | (Empty) | DESTINATION="c:\temp\file.xlsx" | The path and file name in which to save the macro processed workbook upon completion. Click the folder icon to navigate to the destination using an Open File dialog. |
Overwrite if workbook already exists | Yes/No | No | No | OVERWRITE="YES" | If selected, the newly created workbook will overwrite an existing workbook with the same name, If disabled, an error will occur during runtime as a result of a matching file name. This parameter is disabled by default. |
Macro name | Text | Yes | (Empty) | MACRO="theMacro" | The name of the Excel macro to automate. |
Cell reference | Text | No | (Empty) | CELLREF="text" | The cell address that identifies a cell on a worksheet and tells Microsoft Excel where to look for the values or data you want to use in a formula. This parameter uses the A1 reference style, which refers a cell using the column letter followed by the row number (for example, column A, row 10 = A10). |
Use active worksheet | --- | --- | --- | --- | If enabled, specifies that the macro will run on the currently active worksheet. If this parameter is enabled, the Use specific worksheet parameter is ignored. This is a design-time parameter, therefore, contains no markups. |
Use specific worksheet | Text | No | Save | WORKSHEET="Sheet1" | If enabled, specifies the name of a specific worksheet in which to run the macro. If this parameter is enabled, the Use active worksheet parameter is ignored. |
Example
- Copy and paste the sample AML code below directly into the Task Builder Steps Panel.
- To successfully run the sample code, update parameters containing user credentials, files, file paths, or other information specific to the task to match your environment.
Description
This sample task opens an Excel workbook, runs a macro, then saves the workbook with a new file name.
<AMEXCEL ACTIVITY="run_macro" SOURCE="c:\temp\test_macro.xlsx" VISIBLE="NO" DESTINATION="c:\temp\macro_result.xlsx" OVERWRITE="YES" MACRO="Test" CELLREF="A10" WORKSHEET="Sheet1" />