Issues:
SpreadsheetApp.openById("id")
is an instance of the Spreadsheet class.
However, getRange
is a method that can be applied to sheet objects.
Solution:
replace:
var sheet = SpreadsheetApp.openById("id");
with any of the following:
var sheet = SpreadsheetApp.openById("id").getSheetByName("sheetName");
var sheet = SpreadsheetApp.openById("id").getActiveSheet();
var sheet = SpreadsheetApp.openById("id").getSheets()[0]; // 0 indicates the 1st sheet
or even with the part that you commented out:
var sheet = SpreadsheetApp.getActiveSheet();