Running Macros
You can configure the SaveToDB add-in to launch Excel macros, which provides several advantages:
- All user actions are accessible via the Excel context menu and the SaveToDB Actions menu.
- Macros are tied to specific queries and are available immediately after connecting to data.
- Macros can accept input parameters from table columns, query parameters, and named cells.
Macros can reside in active workbooks or in separate macro workbooks that can be updated independently.
Specify macros in the HANDLER_CODE
field using the following format:
<Excel macro> [<Parameter1>[, <Parameter2>[, ...]]
For example:
ID | TABLE_SCHEMA | TABLE_NAME | COLUMN_NAME | EVENT_NAME | HANDLER_SCHEMA | HANDLER_NAME | HANDLER_TYPE | HANDLER_CODE |
---|---|---|---|---|---|---|---|---|
dbo | test | ContextMenu | dbo | Run HelloWorld Macro | MACRO | HelloWorld |
Macros can utilize context values in the following formats: {ParameterName=DefaultValue}
or simply {ParameterName}
.
For example:
SayHello "World" SayHello {Name=World} Sheet1.SayHello {FirstName}, {LastName} MacroWorkbook.xlsm!SayHello {FirstName}, {LastName}
Keep in mind that a macro sheet name is an internal Excel name, not the user-visible name.
You can check macro names using the Excel dialog box for launching macros (Alt-F8).
Important! Only run macros from trusted sources! SaveToDB does not validate macros.