I have an onOpen
execution code but I want it to execute only when a specific sheet is opened (For example on opening Sheet1
the onOpen function should run.) Does anyone know how to achieve this?
Here is what exactly I want to achieve:
- On open of the spreadsheet, check if the active sheet is sheet1. In case it is then execute a condition within that sheet, as shown below:
onOpen() { //If the active sheet is "Sheet1" then perform this: //Sheet Execution comes here. }
But here is the problem with above statement:
onOpen will only check once the sheet is opened. I want to check it every time the active sheet is "Sheet1". So for example, initially the user opens the spreadsheet, they land to "Sheet1" Now the condition is checked and output is displayed, but what if user changes the tab to say "Sheet2" and then comes back to "Sheet1". In that case onOpen()
won't execute. I want to perform my check everytime the user lands or switches to "Sheet1".
Now here's another scenario:
using onSelectionChange
:
onSelectionCHange() { //If the active sheet is "Sheet1" then perform this: //Sheet Execution comes here. }
Now this will work everytime user switches to "Sheet1", but here's the problem, even if user switches to different cells in "Sheet1" onSelectionChange
will be triggered, which is again something undesired. All I want is to only trigger the function each time the tab/sheet is changed to "Sheet1" and not only when the spreadsheet is opened or any selection cell is changed.