Hi all,
I am trying to create my first office script today and unfortunately run into some problems right away.
I have an Excel file where in column L are file names and in column M are links to these files in a SharePoint site.
I now want to set the formula for a hyperlink with a For loop with the file name and the file link in column N.
After that I want to either hide or delete the columns L and M.
The For-loop I have already managed so far, but I have not yet understood how I have to make the setting of the formula for the hyperlink syntactically correct.
Here are my first attempts to set the file name from the L column as the link description:
function main(workbook: ExcelScript.Workbook) {
let currentWorksheet = workbook.getActiveWorksheet();
let usedRange = currentWorksheet.getUsedRange();
let rowCount = usedRange.getRowCount();
for (var i = 1; i <= rowCount; i++) {
if (usedRange.getCell(i, 11).getValue()) {
// usedRange.getCell(i, 13).setFormulaLocal("=HYPERLINK(\"https://xxx.sharepoint.com/sites/CS-Reisekostenabrechnung//Freigegebene Dokumente/ Positionen/number9.png\"; \"' usedRange.getCell(i, 11).getValue() '\")");
// usedRange.getCell(i, 13).setFormulaLocal("=HYPERLINK(\"https://xxx.sharepoint.com/sites/CS-Reisekostenabrechnung//Freigegebene Dokumente/ Positionen/number9.png\"; \"usedRange.getCell(i, 11).getValue()\")");
// usedRange.getCell(i, 13).setFormulaLocal("=HYPERLINK(\"https://xxx.sharepoint.com/sites/CS-Reisekostenabrechnung//Freigegebene Dokumente/ Positionen/number9.png\"; \" & usedRange.getCell(i, 11).getValue() & \")");
usedRange.getCell(i, 13).setFormulaLocal("=HYPERLINK(\"https://xxx.sharepoint.com/sites/CS-Reisekostenabrechnung//Freigegebene Dokumente/ Positionen/number9.png\"; \" ${usedRange.getCell(i, 11).getValue()} \")");
console.log(`The current cell's value is ${usedRange.getCell(i, 11).getValue()}`);
}
}
}
All 4 attempts show then in the column N only the command as string, but not the file name. What would be the correct syntax here?
For deleting or hiding the columns I used the macro recorder. Unfortunately, the macro recorder shows me a syntax error in its own generated code in both cases.
function main(workbook: ExcelScript.Workbook) {
let backup = workbook.getTable("Backup");
// Delete range L:M on backup
backup.getRange("L:M").delete(ExcelScript.DeleteShiftDirection.left);
}
Expected 0 arguments, but got 1 (2554).
If I start the script anyway, then all columns from A to M are either completely deleted or all hidden.
Can anyone help me further here?
Regards
Herb