1

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

mfaiz
  • 475
  • 1
  • 7
  • 17
  • Do you specifically need it from the office script? Could you get it from a calling flow? Assuming the script isn’t executed from directly with Excel by a user. – Skin Aug 27 '22 at 23:54
  • As it stands, it is executed from inside the script, unfortunately. – mfaiz Sep 05 '22 at 08:27
  • Yes, but is the script executed from with **Excel** or from a **PowerAutomate/LogicApps** flow? – Skin Sep 05 '22 at 09:44

2 Answers2

0

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.

A flow showing a OneDrive connector providing the file path to an Excel connector that calls a script.

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.

Alexander Jerabek
  • 358
  • 1
  • 3
  • 10
0

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();