Hopefully a rather simple one but I cannot work out how to get the URL or full path (fullname) for the workbook.
The workbook is https://example.sharepoint.com/sites/abc/x/y/z/file.xlsx
How do I get this path out of office script api
Hopefully a rather simple one but I cannot work out how to get the URL or full path (fullname) for the workbook.
The workbook is https://example.sharepoint.com/sites/abc/x/y/z/file.xlsx
How do I get this path out of office script api
As it stands today, there's not a way to get the workbook's link from a script only running inside Excel. As mentioned in the comments, you can pass this information to a script through Power Automate if you're running the script as part of a flow.
To do this, you'd need to make the script take a string parameter for the URL. Something like this:
function main(workbook: ExcelScript.Workbook, workbookURL: string) {
Then, you'd need to make a flow that gets the workbook path from OneDrive and provides it to the script as input.
In a real flow, you'd probably get the file from elsewhere and use that as dynamic content for the OneDrive and Excel connectors. You can also get the share link from the OneDrive connector, if that's the actual URL you're looking for.
Use a formula. Might want to make sure you put it somewhere it will not be overwritten.
workbook.getActiveWorksheet().getRange("B1").setFormula("");
workbook.getActiveWorksheet().getRange("B1").setFormula("=CELL(\"filename\")");
let filePath = workbook.getActiveWorksheet().getRange("B1").getText();