Hello @qualm
The point of macros is to be fast. Technically, you can pause execution with regular setTimeout()
or setInterval()
methods, but that way you will need to separate execution of the macro in several parts or loop them. Additionally, first part of the macro will be rendered in the spreadsheet, but the second one will be available after another render, because timeouts, even though working, delay all further changes made by macros and thus they are not rendered. Workaround here is to use recalculation methods, but it is important to understand that all additional recalculations take time, so you might get a result, where execution of macro increases in time. Here is an example:
let func1 = function () {
let spread = Api.GetActiveSheet();
let range1 = spread.GetRange("G2");
range1.SetValue("test");
};
let func2 = function () {
alert('executing');
let spread = Api.GetActiveSheet();
let range2 = spread.GetRange("H2");
range2.SetValue("test2");
Api.asc_calculate(Asc.c_oAscCalculateType.All); // recalculating all to display second change
};
func1(); // calling first change
setTimeout(func2, 1000); // calling second change and recalculating after 1 second
Another problem here is that you cannot run alerts from macro directly (see this: Message box with macro) . Basically, with this approach you will increase execution time of your macro. It also depends on the complexity of the macro in general.
You can also check out this reply on promises usage: Macros: SetTimeout() value problem - #5 by Constantine