Reputation: 1483
I found this script that will change a specified worksheet name based on a cell in that worksheet (from here):
function renameSheet() {
var s = SpreadsheetApp.getActive().getSheets()[2];
s.setName(s.getRange(1, 2).getValue());
}
How would I modify this script to change all worksheet names (I'll use a trigger for every hour) based on the B1 cell in each worksheet?
Upvotes: 0
Views: 1593
Reputation: 3728
Replace ID with the spreadheet's ID since it will not be active when accessed from the time trigger
function renameSheet() {
var s = SpreadsheetApp.openById(id).getSheets();
for(i in s) {
s[i].setName(s[i].getRange(1, 2).getValue());
}
}
A spreadsheet ID can be extracted from its URL. For example, the spreadsheet ID in the URL https://docs.google.com/spreadsheets/d/abc1234567/edit#gid=0 is "abc1234567".
Upvotes: 2