I'm running a script below to send email automatically from google sheets using the cell value as the trigger. But I faced this error message when test running the script. Any idea why? thanks
TypeError: Cannot read property 'getSheetByName' of null (line 3, file "Code")
function SendEmail_AutoMedia_nic() { // Fetch the target value var MyValuesRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Master").getRange("H6"); var MyValues = MyValuesRange.getValue(); // Check the target value if (MyValues > 0){ var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("email list") var startRow = 2; // First row of data to process var numRows = 10; // Number of rows to process // Fetch the range of cells A2:B10 var dataRange = sheet.getRange(startRow, 1, numRows, 2); // Fetch values for each row in the Range. var data = dataRange.getValues(); for (var i in data) { var row = data[i]; var emailAddress = row[0]; // First column var message = row[1]; // Second column var subject = 'รบกวนพี่แคทตั้ง Auto Media สำหรับ Mini Program'; MailApp.sendEmail(emailAddress, subject, message); }}}