I know that Google Apps Script has a getSheetId() method for the Sheet Class, but is there any way to select a sheet within a spreadsheet by referencing the ID?
I don't see anything like getSheetById() in the Spreadsheet Class documentation.
I know that Google Apps Script has a getSheetId() method for the Sheet Class, but is there any way to select a sheet within a spreadsheet by referencing the ID?
I don't see anything like getSheetById() in the Spreadsheet Class documentation.
You can use something like this :
And then to find the sheet ID to use for the active sheet, run this and check the Logs or use the debugger.
Look at your URL for query parameter #gid
https://docs.google.com/spreadsheets/d/1Vk7kzMD3DhfUeLasDdSK6Z9ScNrryPrawAxHGFimKp8/edit#gid=910184575
In example above gid=910184575, so you can do something like this:
Try
openById(id)
as outlined in in Google's documentation:Reference: https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#openById(String)
Not sure about ID but you can set by sheet name:
The SpreadsheetApp Class has a setActiveSheet method and getSheetByName method.