Accessing a Google Sheets document using its name

Hey everyone! I'm working on a script that adds data to a Google Sheets document. The problem is that the sheet gets too big after a while.

Right now we have to move stuff from the main sheet to a new one by hand. This is because not everyone knows how to change the sheet ID in the code.

I'm wondering if there's a way to open the sheet just by using its name. If that's not possible, does anyone have ideas for a better way to handle this situation? Maybe some kind of automatic sheet switching or data archiving?

Any suggestions would be super helpful! Thanks in advance!

While accessing a Google Sheet by name isn’t directly supported in the API, there’s a workaround you could implement. First, use the Drive API to search for the sheet by name, then retrieve its ID. With that ID, you can access the sheet through the Sheets API as usual.

For your specific problem, consider implementing an automatic archiving system. You could set up a trigger to run periodically, check the sheet’s size, and if it exceeds a certain threshold, create a new sheet, move older data there, and update the main sheet’s ID in your script.

This approach would require some initial setup but could save a lot of manual work in the long run. It would also eliminate the need for non-technical users to modify the code.

hey there! have u thought about using google apps script? it lets u search for sheets by name. u could set up a script that automatically creates new sheets when the old one gets too big. might save u some headaches! just an idea tho, hope it helps :slight_smile:

As someone who’s dealt with similar issues, I can share what worked for me. Instead of accessing the sheet by name, I created a separate configuration file (like a JSON or simple text file) that stores the current active sheet ID. My script reads this file to get the sheet ID, so when we need to switch sheets, we just update the config file.

For archiving, I set up a scheduled task that runs weekly. It checks the row count, and if it exceeds a set limit, it creates a new sheet, moves older data there, and updates the config file with the new sheet ID. This way, the main script always works with the current sheet without manual intervention.

This approach has saved us tons of time and reduced errors. It might take a bit to set up initially, but it’s been a game-changer for our team’s workflow.