0

From Quickstart: Macros, Menus, and Custom Functions I know how to add my script to my spreadsheet:

Tools > Script editor, Blank Project, delete any code in the script editor and paste in the code.

it called bounded script (Scripts Bound to Google Sheets, Docs, or Forms).

but what if I need to pass (already written) script to another user, so that user would be able to apply this script to his own spreadsheets?

Bruno Gelb
  • 5,322
  • 8
  • 35
  • 50
  • @teatimer ye, or add that script to original spreadsheet by myself. But what if that person have another files where he could use the script? – Bruno Gelb Jan 13 '15 at 06:43

1 Answers1

1

If you don't want to share the code or let them edit, you could use a library. All sheets must have the code

in the bounded script:

function onOpen(){
  libraryName.createMenus();
}

That's it, you'll have access to all methods that you display in the createMenus(), these which should also call the function with the libraryName identifier behind it, as such:

  var fun = 'libraryName.'
  SpreadsheetApp.getUi().createMenu('Load funcs').addItem('first func', fun+'anyFunc').addToUi();

And for debugging add the library to itself.

Also he can use any function by calling libraryName, it even shows in autocomplete all functions in the library.

Kriggs
  • 3,731
  • 1
  • 15
  • 23
  • Note that library code is still easy to access and copy. It just protects your copy from edits. – Henrique G. Abreu Jan 13 '15 at 12:34
  • @HenriqueAbreu, how do you copy all the library code just with the identifier and no access? – Kriggs Jan 13 '15 at 12:46
  • You click on Resources > Libraries, then on the library title, opening a tab with its documentation. In this tab URL you can easily grab the library KEY. With this key you just grab any script URL and replace it `https://script.google.com/macros/d/<>/edit`. The library will open normally in "view" mode, since the library must be share with at least view only with the user in order for one to use it. – Henrique G. Abreu Jan 13 '15 at 13:32
  • @HenriqueAbreu `[...] library must be share with at least view only[...]`, didn't know that. – Kriggs Jan 13 '15 at 13:41