简体   繁体   中英

function to name range google app script

I'm very new to this so I apologize for any missing info in advance. I am trying to make a function that sets a range in any document I use it in. Here is my code at the moment:

function nameRangeDocDate() {

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Logs");

var rangeToName = sheet.setRange(1,1);
var rangeName = "DocDate";

ss.sheet.setNamedRange(rangeName, rangeToName)

}

Whenever I run the function I get the message: "TypeError: Cannot call method "setRange" of null. (line 6, file "we")". Can anyone explain to me what is wrong with my code? Am I missing something or is my code just wrong?

setNamedRange() is a method of Spreadsheet class.

ss.sheet.setNamedRange(rangeName, rangeToName)

should be

ss.setNamedRange(rangeName, rangeToName);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM