Search code examples
javascriptgoogle-apps-scriptgoogle-sheetscustom-function

Google Sheets Script to refresh the script to get the name of the spreadsheet


I use a script that creates a formula to get the name of the spreadsheet.

But this formula never refreshes, neither when I change the spreadsheet name nor when I reopen the spreadsheet.

I would like if it is possible that it refreshes when I change the name of the spreadsheet. If not possible, at least when I close and reopen the spreadsheet.

Here is the script:

    function SPREADSHEETNAME() {
  let ss = SpreadsheetApp.getActive();
  return ss.getName();
}

I execute this function with this formula:

=SPREADSHEETNAME()

Thanks in advance.


Solution

  • 2 solutions

    • onOpen : execute the script with a slight modification, thsi script will give the address where the name will be put

    • add a dummy parameter as a checkbox, for instance in A1 and put =SPREADSHEETNAME(A1)

    the last possibility is, when opening the spreadsheet, change the value of A1

    however, if you change the name manually when the spreadsheet is open you will have to change the value of the checkbox to refresh