0

I manage about 30 Google spreadsheets for my department. Each of them uses the same 1000 lines or so of code (Google Apps Script) for various maintenance tasks. Each time I need to update the code, which is often, I have to open each spreadsheet, open the script editor, and paste the code in.

Obviously, this is very time-consuming and inefficient. I need a way to update all of them at once. Using a library would slow them down too much, and the ScriptApp does not seem to have any methods that can do this.

I would greatly appreciate any help you can provide. Thank you for your time.

CMena
  • 13
  • 2
  • It *is* possible to update a target Apps Script file from a source Apps Script file. It's also possible to update and Apps Script file from an external source. I think that some code editors can update an Apps Script file, but not sure which ones. You can get more information at the following Apps Script post. [Link StackOverflow](http://stackoverflow.com/questions/34474625/update-overwrite-one-apps-script-file-with-another-apps-script-file-using-apps) I do have some code posted publicly at GitHub concerning a similar issue. My code doesn't do multiple files at once, but has a file pkr – Alan Wells Jun 14 '16 at 18:11
  • 1
    @SandyGood - Presumably, the question here is about scripts contained in spreadsheets. Aren't you talking about stand-alone scripts being updated? – Mogsdad Jun 14 '16 at 19:00
  • Oh, yah, I'm talking about stand-alone. Sorry about that. Have you looked at using an Add-on? – Alan Wells Jun 14 '16 at 19:54
  • You should use an unlisted Add-on. Updates are automatic to the user. – Alan Wells Jun 14 '16 at 19:59
  • Okay, I will try that. Thank you! – CMena Jun 15 '16 at 20:23

1 Answers1

1

I do this by having all the spreadsheets use a single library and 3 lines of code:

/*SPREADSHEET CODE*/
function onOpen() {
  myLibary.onOpen();
}

But the library functions should point to themselves:

/*LIBRARY CODE*/
function onOpen() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var ui = SpreadsheetApp.getUi();
  var menu = ui.createMenu("MyMeny");
  menu.addItem("Item", "myLibrary.function");
  menu.addToUi();
};

Else: You could use the Add-on possibility and deploy the script to your users using the add-on.

Riël
  • 1,251
  • 1
  • 16
  • 31