r/GoogleAppsScript • u/_itskittyy • May 15 '25
Question Using multiple files for one sheet?
Hi ☺️ I’m new to this and have been learning as I go.
I have a google sheet with multiple tabs that I have been working on. I have two separate files in App Script that work when alone but they won’t work together
Do I have to combine it in one file somehow or is there a way to have two files for one sheet and them both work?
Thank you in advance. Anything helps 🩶
1
Upvotes
4
u/mommasaidmommasaid May 17 '25 edited May 17 '25
How I handle this kind of thing:
Multiple onEdit
You can rename your existing onEdit() functions and leave them in their respective .gs files, or if that's all that is in them I'd just combine them all into one .gs file for convenience.
I cleaned up the code, added some constants, and check the fastest exclusions first so it returns as quickly as possible if it's not an event the script needs to handle.
I also unchecked the checkbox in the row hide function so it's ready to go again, idk if you want that and/or you may want to add it to the timestamp function.
Note that neither function as written handles multi-cell edits (e.g. if user selects multiple checkboxes at the same time and hits Space).
3
u/Gwaelan May 15 '25
What are the names of your functions? Are they both called OnEdit?
1
u/Operation13 May 15 '25
The files in a single GAS project will all ‘talk’ to each other. Don’t need to combine them, although you can, but the problem could be a number of things.
What does the first file do? And what about the second?
2
u/OddCandy2841 May 16 '25
Can't have two onEdits... Change the name of one of the functions to something else and build a trigger for both. The trigger will be what fires it on edit.
2
u/Mudita_Tsundoko May 16 '25
No need. When you call a function, all the script files are automatically combined into a single file before running; so unless you'd like to do this for personal reasons, there's really no need to do so from an operational standpoint.