I am trying to send emails from a spreadsheet. The script grabs the emails and the body of the email from a sheet within the spreadsheet. When this sheet is the first sheet, the script works fine. However, for reasons that I won't go into I need another sheet to be first. I have tried using:
var ss = SpreadsheetApp.getActive.Sheet();
var sheet = ss.getSheetByName('Email');
However, when I do this I get the message
TypeError: Cannot find function getSheetByName in object Sheet. (line 3, file "Code")
Is there another way to get the script to get information from a sheet besides the first sheet in a spreadsheet?
To get a sheet in a spreadsheet you need to use a method that belongs to a sheet parent's class, in other words, a method from the spreadsheet class.
Spreadsheet is the container of all its sheets, that is a basic concept.
So simply use a code like below :
var ss = spreadSheetApp.getActiveSpreadSheet();// this gets you the active spreadsheet in which you are working
var sheet = ss.getSheetByName('emails');// if the sheet you want is called 'emails
You could easily avoid such simple problems by making use of the autocomplete feature included in the script editor : simply type spread followed by CONTROL SPACE and you'll see all the available methods in this context, the first one will be spreadSheetApp
, then type a dot (.)
and you will see all the methods in that class and the type of object it returns... choose the one you need and continue like that al along.
see an illustration below :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With