简体   繁体   中英

Google Sheets “Script Function Could Not Be Found”

First time posting here and a newbie at javascript, so hoping this is a very simple fix. I have created an appendRow script (after following a few different examples and amending them for my use). The intention is to have 4 cells at the top of a Google Sheet that are automatically added to the bottom of data in columns A, B, C & D.

Code:

var headers = ['Today' , 'Month' , 'Total Value' , 'Cash Invested'];
var data1 = ['Today' , 'Month' , 'Total Value' , 'Cash Invested'];

var data = [headers , data1];

function putMultipleValues()
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("VG Investment Value");
  sheet.appendRow(['=a5','=b5','=c5','=d5']);
}

All is working ok, except that the only way I have found to connect the button to the script is by using the 'Select function' name "putMultipleValues". If I use the name of the script (that I have given it) - "VG Table", a "script could not be found" error shows.

This would not be an issue, except I would like to use an almost identical script on a different, almost identical, sheet. The trouble is that this new script also has the 'Select function' name "putMultipleValues" so both scripts fail.

Does anyone know how to change the button so that it links to the script's name rather than it's function?

Many thanks in advance.

Hi and welcome Markrc !

I don't have much experience in Google Script, but from what I understood, a Spreadsheet (and its sheets) is connected to a Script Project . This Script Project can contains one or more script files . Each Script files can one or more functions .

The function is what Google Sheet will call a script . (I know, this is a bit confusing) You can link a script to a button, wich means you can link a function.

However, if you use global variables in your script, the function can access to it (as you noticed). You can link different buttons to different scripts (functions), but you can not link a button to a Script Project or a Script File.

I am not 100% sur of this, but this is how I think it works. If anyone could confirm it, it would be great.

Hope it helped !

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