Extending product function with VBA > Running a macro > Run a macro on starting System Architect
  
Run a macro on starting System Architect
A macro can be configured to be run on starting System Architect.
This allows execution of the macro from the command line to allow macro execution to be scheduled through Windows Task Scheduler.
Assumptions
The macro must be specified to be loaded through Tools\Macro Projects so that it is loaded.
The macro must be compiled (error free).
The client is responsible for ensuring the macro will handle errors and that a user will be on hand to respond to any user interface presented.
If the macro requires an encyclopedia to be open then it must either open one through Application.OpenEncyclopediaUsing* or a default encyclopedia should be configured, for instance through the -encyclopedia connection_name(ency_name) command line switch.
If work is to be performed on a number of encyclopedias then the macro can open them in sequence.
System Architect should shut down after running the macro.
Command line parameters
The following command lines (to be specified after the System Architect executable – for example, ..\sa2001.exe -command) are supported – these are not case sensitive.
-ExecuteMacroOnStart project.module.routine
where the elements of the macro identification are not case sensitive.
-ExecuteMacroOnStartArg string
where string will be supplied as an argument (parameter) to the macro. The macro is then responsible for processing it.
Logging
Example
commandline: path\sa2001.exe -executemacroONSTART tesT.autoexeC.testMsg -executemacroonstartarg hello
Log
04/02/2021 12:08:25 elapsed:78.0638 Ver:11.4.8.1.30 - Startup Complete 78.083 sec
04/02/2021 12:08:25 elapsed:78.1378 Ver:11.4.8.1.30 - SA Fully started
04/02/2021 12:08:25 elapsed:78.1521 Ver:11.4.8.1.30 - SAUI Initialized
04/02/2021 12:08:25 elapsed:78.1673 Ver:11.4.8.1.30 - ExecuteVBAMacroCommand2: tesT.autoexeC.testMsg("hello")
04/02/2021 12:08:25 elapsed:78.1933 Ver:11.4.8.1.30 - ValidateMacro returned 0: Ok
04/02/2021 12:08:27 elapsed:80.3346 Ver:11.4.8.1.30 - VBA - Executed : Test,autoexeC,testMsg
04/02/2021 12:08:27 elapsed:80.3426 Ver:11.4.8.1.30 - ExecuteMacro returned 0
04/02/2021 12:08:27 elapsed:80.3596 Ver:11.4.8.1.30 - Shutdown requested.
On failure
In the event of failure to process the execution, such as not finding the macro or the macro is not executable due to a compilation error, this message is logged.
"ValidateMacro returned code: message", where message would be one of the following messages:
"No project of that name exists"
"No module of that name exists"
"No procedure of that name exists"
"Unable to compile the project"
"No permission to execute that macro exists"
- this refers to role based access control permissions
"The string passed in is incorrectly formatted"
"There was an unknown error"
On success
"ValidateMacro returned 0: Ok" will be logged.
"ExecuteMacro returned 0" will be logged.
Automation considerations
It is important to remember that if the macro is to be run unattended then it should not be presenting user interface dialogs or message boxes to report errors.
See also
Loading a macro project
Macros provided with System Architect
Running a macro