Rename Form Tab Automation in Google Sheets
Learn how to automate the creation and renaming of Google Forms directly from Google Sheets using Apps Script. This tutorial walks you through the process of setting up a custom menu and managing form responses efficiently.
So we're creating a sheet, and sometimes we need information to come from outside the sheet. Someone wants to enter data and we want to give them data validation . We use a form for that, and usually what you're gonna do is go up to tools and create a form. But what if we want to create a form automatically? This could be for a variety of reasons. Maybe we're creating a template . That we want to have someone else create that form or we want to create a form, let's say once a month, once a week for different classes. Variety of reasons why you may want to not just click create a form. So we're gonna go up to Extensions app script it. And here we're gonna create a function called create form.
I don't want to come over here to this function and hit run, I'm gonna go over to Better Sheets co slash snippets, totally free page over at Better Sheets at co. I'm gonna grab this Create menu function . I'm gonna add this here at the bottom. And we're gonna add this form. And so we're adding an item over here next to help that's going to allow us to create a form. So let's create that function that we're going to call. We need a variable form, which is equal to form app. Do create. And here we're gonna give it a title, new form, and we can set the title here, brand new form. I just want to get a ID of this. But let me show you what this does first and why we need to rename the tab. We are gonna review permissions the very first time we run it.
We have an ID and it is not connected to our sheet, so we need to set that connection. So we're gonna do form set destination, and we're gonna do form app dot destination type dot spreadsheet . And that's all there for us in the auto fill , comma. And now we need the spreadsheet id . So we can do spreadsheet , app, docket, active spreadsheet , docket id. This could be the sheet ID as a variable bowl that might look a little bit better for you. Let's save that and let's run this again. And now we have what's called form responses one. Well, this is the point of this video is we want to rename this form responses one. If we go over to our form, let's edit our form. You can see it's called brand new form, so that's correct.
But that title is not showing up here on the tab. So let's do that. Lemme get the form id and that's form Get id. And now there is no form URL . So if we do form URL equals form, do get URL. See there is some edit URLA summary, URL published URL, but we can actually make our own URL. That's going to be docs.google.com/form/d/what could that be? Well, it's gonna be the form ID plus we gotta end it with slash view form. Now this URL is gonna be very, very useful because what we can do is check this sheet for a form URL and actually we can check every single sheet. Every single sheet we can check. Does it have a form URL , yes or no?
And it does. What is it? So we're gonna do variable sheets equals spreadsheet , app dot get active spreadsheet . It's there. And get sheets. And now we have an array of all the sheets in the form. Alright, well, sorry. All the sheets. All the tabs in the spreadsheet . And now this might be a little difficult, but it is very, very. Cool. To be able to see how this comes around is we're gonna say for, we're gonna start at I equals zero. We're gonna go as long as sheets do length, meaning there is some amount of sheets in our spreadsheet and we're gonna know that by going sheets length. And then we're gonna keep iterating eye until we get that all that way.
And we're gonna add one every single step of the way. This is a for loop. And if Sheets square bracket I is equal to form URL . Actually, sorry, if the square brackets get form URL , so we can get the form URL of every, every single sheet. And then once it's equal to this form URL that we've created, well, what are we gonna do? We're gonna take that sheets. I. And square brackets, and we're gonna set the name and we're gonna set the name to the exact same title of this form. And so we can call this like form title equals this and set this title and the set name to form title. So now let's close this and refresh our sheet. I'm gonna actually unlink this one and delete it, just so I can show
you again how this automation works. We have a custom menu at the top. That was our snippet here that we copied on open. Every time we open the sheet, it adds this menu. Custom menu now create new form and it's created a form. And you saw for a split second it said form responses two, because every time we create a new form, it's gonna say form response. 2, 3, 4, 5. It's gonna iterate. But this one changed its name to brand new form. This is pretty cool, and this is a lovely way to be able to name that form inside of your sheet. Pretty cool right Extensions app script , and there's the entire automation right here for you. Thanks for watching. You are watching better sheets here on YouTube. Make sure you check out this video or this video and subscribe right
now to get more tips, tricks, how tos, get more out of your Google sheets than you ever have before. I'm excited to be making a ton more videos here. Ask me questions down in the comments and I will answer them in future videos. But for right now, right here, one of these videos is gonna be your next Google sheet.