Having one script for multiple receivers(files)

94 views
Skip to first unread message

Paul

unread,
Sep 21, 2022, 11:12:39 AM9/21/22
to Google Apps Script Community
Hello, ladies and gentlemen! 

I have a google app script that is used for different google excel files. How could I have only one script and to make it work for all the files I need. At the moment the process is following: I want this script to work for a particular file.. I go to Extensions => Apps Script and add the code. Then I realise that I need (for example) 3 more such files and I do the same process again. And if I by any change will want to fix that script somehow I would have to change it in every single file I used before. I want it to work different. I want one script and several receivers, so that I could change one script that will affect all dependent files. 

How could I achieve that ? 

Thanks in advance! 

CBMServices Web

unread,
Sep 21, 2022, 12:46:03 PM9/21/22
to google-apps-sc...@googlegroups.com
Hi Paul,

You can have a standalone Apps Script file and it can still make changes and additions to any spreadsheet if you give it the right permissions.

Issue becomes more how you direct it to pick a particular Spreadsheet to modify.

The other question is whether you need particular triggers on that Spreadsheet like on Open, on edit or on change. If you need such triggers, there is no alternative but having some minimal script in the Spreadsheet container.

For changes to be effective across multiple spreadsheets, you can make the large bulk of your code into a library and then just invoke it from a very small script in the Spreadsheet.

So up it is to your situation  and what you prefer doing.


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/260e3dac-6ba6-4249-8648-3b0f7b638658n%40googlegroups.com.

Paul

unread,
Sep 22, 2022, 3:44:14 AM9/22/22
to Google Apps Script Community
Hi George,

Thanks for your answer!

> You can have a standalone Apps Script file and it can still make changes and additions to any spreadsheet if you give it the right permissions.

I am not quite sure what you mean by that. Did you mean the process that I described earlier(when I manually add the code to every single file I am interested in) ? 

> The other question is whether you need particular triggers on that Spreadsheet like on Open, on edit or on change.

> For changes to be effective across multiple spreadsheets, you can make the large bulk of your code into a library and then just invoke it from a very small script in the Spreadsheet.

In my case I do not need any triggers I believe. I just have a menu option and when I choose it, it executes the code I need. Sometimes I need to fix the code, or add some additional functionality. But following the process I described earlier it is not possible. Could you please a bit enhance your answer with details or links to how to do what I want?

среда, 21 сентября 2022 г. в 19:46:03 UTC+3, George:

Andrew Roberts

unread,
Sep 22, 2022, 4:04:03 AM9/22/22
to google-apps-sc...@googlegroups.com
> I am not quite sure what you mean by that. Did you mean the process that I described earlier(when I manually add the code to every single file I am interested in) ? 

You would have one stand-alone script and it would use the IDs of all the Sheets it needed to access with openById() rather than getActive(). These could be hard-coded, or pulled out of a "main" GSheet.

Personally I'd make the stand-alone script a library, and have a minimal script that calls it from the bound script of each GSheet. 

Paul

unread,
Sep 22, 2022, 5:44:05 AM9/22/22
to Google Apps Script Community
Thank you! 

May I ask one more stupid question ? ) You've mentioned the references to other sheets so I would need to kinda global script. How could I run it and where should I put it to ? I mean I know how to affect single file(where should I put the code to).. Or you mean that I would need to put it to one sheet file.. lets call it "main sheet" and put that script to it ? 

четверг, 22 сентября 2022 г. в 11:04:03 UTC+3, and...@roberts.net:

Andrew Roberts

unread,
Sep 22, 2022, 6:09:15 AM9/22/22
to google-apps-sc...@googlegroups.com
That's right, a "global" script. 

Go to script.google.com and use the "New Project" button to create a stand-alone script - one that isn't "bound" to any particular GDoc. This doesn't mean it can't access any GDoc if it has its ID (via openById()).

Paul

unread,
Sep 22, 2022, 6:14:57 AM9/22/22
to Google Apps Script Community
Got it! Thank you so much! 

четверг, 22 сентября 2022 г. в 13:09:15 UTC+3, and...@roberts.net:
Reply all
Reply to author
Forward
0 new messages