Thanks for sharing! If I'm understanding correctly, your script is trying to create a table over the used range in a worksheet, and the file/workbook is a dynamic parameter passed into the run script action?
If so, then your error is probably because you're running the script on a worksheet that already has a table somewhere. You could check this by modifying your script like so:
function main(workbook: ExcelScript.Workbook) {
let selectedSheet = workbook.getActiveWorksheet();
if (selectedSheet.getTables().length > 0) {
console.log('This worksheet already has a table. Stopping script.');
return;
}
// Add a new table at range A1:AC141 on selectedSheet
let newTable = workbook.addTable(selectedSheet.getUsedRange(), true);
// Rename table newTable to "Charge_Data"
newTable.setName("Charge_Data");
}
It'd also be helpful to understand how you pass the file parameter into the run script action (i.e., show the previous steps of the flow).