0
votes

I'm using this script to return the ID of an open spreadsheet:

    function getId() {
        SpreadsheetApp.getActiveSpreadsheet().getId()
    }

In the cell, I've added:

    =getId()

The problem is, when I copy the spreadsheet, the new spreadsheet returns the ID for the original spreadsheet - not the ID for the active sheet.

If I enter =getId() in a new cell in the active sheet, it returns the correct ID. So the script is apparently working, it's not just not 'refreshing' the data for a copied sheet.

(Bizarrely, this has worked before! I don't know what's changed but it's stopped returning a new ID value.)

Can anyone suggest how to make sure the ID for the active sheet is shown?

1

1 Answers

1
votes

Your code for function getId() didn't work for me when calling from a cell using =getId(), it's not returning anything at all.

Try this instead:

function getId() {
  var id = SpreadsheetApp.getActiveSpreadsheet().getId();
  return id;
}

This should return the Spreadsheet ID using the formula, I've tested making a copy of the sheet and it updates as expected.