Home > database >  How to auto-run Google Apps Script on my shared file
How to auto-run Google Apps Script on my shared file

Time:06-14

I have a google sheet and share for my friends. I create some convenient menus on it by google apps script. But my friends shared sheet do not know how to run or use google apps script. Can the script auto-run when I open my sheet, and my friends too?

Thanks for reading

CodePudding user response:

Yes, definitely possible.

You would have to create an installable trigger.

function scriptSetup() {
  createOnEditFunction();
}
 
function createOnEditFunction() {
  const ss = SpreadsheetApp.getActive();
  ScriptApp.newTrigger('onOpen')
    .forSpreadsheet(ss)
    .onOpen()
    .create();
}

function onOpen(e) {
  //your stuff here
}

This way, the scriptSetup() is located on the first line so when copying a spreadsheet I would ask the other party who wants to use Sheets to click on Extensions > Apps Script > Run.

You can read more about installable spreadsheet triggers and how to manage them.

  • Related