0
votes

What am I doing wrong with this?

Error code TypeError: Cannot find function activate in object true. (Line 12, file "Code")

Look at past Stack Overflow examples, nothing seems to work. The only way I can get this to run is if I ref the sheet as a number.

  var ss = SpreadsheetApp.getActiveSpreadsheet(); //changed sheet to ss added Spread to Sheet
  var sheet=ss.getActiveSheet().getSheetName()=="LN CX 2019"
  sheet.activate()

I would like to run a script on a specific sheet in a workbook. I cannot lock the tabs so using sheet reference [0] may be a problem in the future.

1

1 Answers

2
votes

We know a Spreadsheet contains multiple Sheets (or 'tabs' of tables) where your data is stored. Within the Spreadsheet, you are trying to get the name of the Sheet, rather than the Sheet object itself.

The simple solution; 1. Get the active Spreadsheet. 2. Get the sheet by name. 3. Activate the sheet.

var ss = SpreadsheetApp.getActiveSpreadsheet(); //Get the active Spreadsheet.
var sheet=ss.getSheetByName("LN CX 2019"); //Find the sheet we want.
sheet.activate() //activate that sheet.

Where you went wrong:

var sheet=ss.getActiveSheet().getSheetName()=="LN CX 2019"

This would return a string of the name of the active sheet, then compare it to another string, returning a boolean value to var sheet making it true or false. Then you are trying to run activate() on that boolean variable (which doesn't exist).