1
votes

I have a spreadsheet with twelve sheets, one for each month of the year. I'd like to have the sheet matching the current month set as the active sheet by default whenever the spreadsheet is opened.

Seems easy enough:

function onOpen() {
  var today = new Date();
  var ss = SpreadsheetApp.getActive();
  ss.setActiveSheet(ss.getSheets()[today.getMonth()]);
}

Unfortunately, SpreadsheetApp loads the first sheet (January) first, then loads the sheet I want. On some mobile clients, this results in an unacceptably long load time.

Is there a way to hook into the sequence before the first sheet in the spreadsheet is loaded as the active sheet?

1
Is it feasible for your solution, which place the sheet of the current month as the first sheet of the spreadsheet? You can have a timer every first of the month to move the sheet.wchiquito
@wchiquito: I like this solution ... very 'outside the box'. It will certainly do for now. I'm still hoping there is a hook into the process earlier on, though.mdtsandman
I agree with @wchiquito, the best way is to run a job at midnight on the first of the month to change the order of the sheets. I dont think there is any other away considering that google spreadsheet first opens and then runs the onOpen function :).Abhishek Ram

1 Answers

0
votes

Another option would be to create a blank first sheet, which should load fairly quickly. Then switch to the current month.