I wrote a script for a spreadsheet template. My user makes copies from the spreadsheet template and the attached script. There are many such instances both spreadsheet and the script. When I update the script for the spreadsheet template, I(or my user) have to manually update all scripts attached to spreadsheets. All scripts are the same. Is there a way to synchronize the script update automatically?
What you can do is maintain a single standalone script and publish it as a library instead of having it reside in the spreadsheet template. This way, you have to change the script in only one place.
To work with triggers such as onOpen, onEdit etc. you can have shell functions in your spreadsheet template. Something like
function onOpen(e){
LibraryName.onOpen(e);
}
Related
I am very new to Google Apps Script. I created a Macro in Excel with VBA. My process is downloading a CSV that I save to my hard drive, opening it (my PERSONAL workbook is open at all times) and then running my macro which will format the list/perform the steps of my macro. I would then save and manually upload that list back to Google Drive.
This is obviously inefficient and The rest of my team uses Google Drive/ Google Sheets and so I am attempting to teach myself how to build out the same macro in Google Apps Script. I understand the difference between bound and unbound scripts - this is similar to Excel in the sense that if I wanted to run my macro on multiple sheets, I would have to save it to my PERSONAL spreadsheet where I stored all of my macros and then have that sheet open at the same time that I ran the macro on a different spreadsheet.
However, for Google Apps Script, it appears as though you simply cannot run a macro through multiple different workbooks without manually copying and pasting your code to every new spreadsheet. Is this true? I see that it could be added in the app store and published as an add-on but my script is painfully basic, I'm just changing some words and formatting. It seems odd that this cannot be applied to multiple spreadsheets the way that it can in Excel. My goal was to use something like:
function onOpen(e) {
SpreadsheetApp.getUi() // Or DocumentApp, SlidesApp, or FormApp.
.createMenu('List Upload')
.addItem('Format List Upload', 'formatListUpload')
.addToUi();
where formatListUpload would run my formatting script so that my coworkers could just click "Format List Upload" as a menu option and the new spreadsheet they had just opened would be quickly formatted. This seems like base-level functionality for macros/ app script. Is there truly no way that this can be done?
Many, many thanks!
From the question
However, for Google Apps Script, it appears as though you simply cannot run a macro through multiple different workbooks without manually copying and pasting your code to every new spreadsheet. Is this true?
No
Is there truly no way that this can be done?
Instead of using a simple trigger you might use an installable trigger, but this option is limited to create 20 triggers by script / user. To make this work you will need somehow to open the spreadsheet i.e. SpreadsheetApp.openById(spreadsheetId)
Options to avoid having to create an add-on
One option that doesn't requires installable triggers is to submit the spreadsheet having the macro to the templates gallery and use the template to create the new spreadsheets
Another option is use script to create a new spreadsheet and the installable trigger for it.
One more option is to create a new spreadsheet, grab the spreadsheet id, either manually or programmatically, then use it to create the installable trigger for the new spreadsheet.
According to Google Apps Script, container-bound scripts https://developers.google.com/apps-script/guides/bound is limited to that file.
I wrote a script that reads some values of GSheet and submits it to the server.
But I also want this spreadsheet to be cloned for different usages. But each time I clone this spreadsheet, it creates a new container-bound script and it asks for permissions again.
Is there a way to clone the spreadsheet and have it run the script without asking for permissions again?
I need to add the same container-bound script to hundreds of google sheets in order to automate a process. I have a separate spreadsheet that catalogues the URLs of all the sheets in need of updates.
Does anyone know how to write a script that will update (and save) script within the script editor based on the sheet's URL? Currently, I'm opening each spreadsheet individually and saving script.
I created a google app script that is bound to google sheet later I moved it as standalone script inside a google drive folder. I thought I will be able to reuse it across multiple sheet. Now I am not able to find any way to run standalone script inside my google sheets. Please suggest.
From your standalone script you can access your spreadsheets and work this way with your files.
Use something like this to get a set of spreadsheets (pseudocode)
var ssList = ['...','...']
for each element in ssList do:
SpreadsheetApp.openById(ssList[element]);
Then you can reuse your code and access multiple spreadsheets.
But it is not possible to access multiple apps script files, only one file is bound to your spreadsheet.
I am looking to locally use a Google Apps Script with one of my Google Sheets (Attached to a form) that will be accessible to all emails that have permission to access the sheet, but I don't plan on publishing this script to the public. Do I still need to publish in order to use this script, or will I be fine just adding an onSubmit function for my Google Form as a trigger for my script to run in my Google Sheet? And can I use installable triggers if I plan on operating this script as a standalone only attached to this one Google Sheet?
Do I still need to publish in order to use this script
No: If you own the spreadsheet (or have editor permissions on it), your script can remain private. A script does not need to be bound to a Spreadsheet except if it will use:
Spreadsheet UI (getUi(), custom menus, dialogs and sidebars)
"Active" items (getActiveSpreadsheet(), getActiveSheet(), getActiveRange(), getActiveCell())
...will I be fine just adding an onSubmit function for my Google form as a trigger for my script to run in my Google Sheet?
Yes: Your standalone script can have installable triggers associated with Google Apps items such as spreadsheets, documents and forms.
And can I use installable triggers if I plan on operating this script as a standalone only attached to this one Google Sheet?
Yes: There's nothing special about the 1:1 relationship; the same trigger could be installed for multiple spreadsheets.