I'm trying to automate a new workbook each 1st working day of the month which create a table with all the working days of that month.
Using the record functionality I was able to create the script and the script is working when I run the script in Excel (desktop and online).
However, when I try to create a power automate flow using this script I get an error:
"We were unable to run the script. Please try again.
Office JS error: Line 4: Range setFormulasLocal: The argument is invalid or missing or has an incorrect format."
Script:
function main(workbook: ExcelScript.Workbook) {
let selectedSheet = workbook.getActiveWorksheet();
// Set range A1:B3 on selectedSheet
selectedSheet.getRange("A1:B3").setFormulasLocal([["Week","Date"],["=WEEKDAY(B2)","=WORKDAY(EOMONTH(TODAY();-1);1)"],[null,"=WORKDAY($B$2;SEQUENCE(NETWORKDAYS($B$2;EOMONTH($B$2;0))-1))"]]);
// Set format for range B:B on selectedSheet
selectedSheet.getRange("B:B").setNumberFormatLocal("d-m-jjjj");
// Auto fill range
selectedSheet.getRange("A2").autoFill();
// Set range A2 on selectedSheet
selectedSheet.getRange("A2").setFormulaLocal("=WEEKNUM(B2)");
// Auto fill range
selectedSheet.getRange("A2").autoFill();
It looks like the way the formula was used in the script is not working in the power automate flow.
Anyone has more experience with this or have an alternative?