How to Create a Custom Automation Menu in Google Sheets
Learn how to create a custom automation menu in Google Sheets using App Script, allowing users to easily access functions and links directly from the spreadsheet interface.
So I have this freebie called Big Year. It's available@bettersheets.co slash big year. But what I wanna do right now is create a custom menu . Now, why am I gonna do this? I'm gonna create some automations around calendars and about this calendar. And before I create the automations, I just want the bare bones structure the. Custom menu up here next to accessibility so that users can get used to clicking that and seeing some things. So I'm gonna go up to Extension's app script , and this really couldn't be easier. It's just a few lines of text, a few lines of code follow along with me as I do this. We're gonna call this big year. That's the project name inside of App Script inside the sheet. So every sheet has this app script that's attached to it that you can edit and do some cool automations with.
The very first function we're gonna write is called on Open. And what this text is on open with a capital O, well, ON, not capitalized, but open, capitalized, is that we're going to trigger this every time we open the spreadsheet . But how do you do that? Well, you just type in function on open. That's how simple it is. You just need to know that. Then we're gonna, what's gonna happen when we actually open the spreadsheet ? Well, we need our spreadsheet ui, which is variable UI equals spreadsheet app. Get UI with parentheses and we go ui, do create menu. Now what this could be is you might not need the variable. If you wanna do it as simple as possible, you just do spreadsheet , app dot get ui.
Create menu and inside of the parentheses here, we're going to put the name of the menu. Now a lot of tutorials show you custom menu . I'm gonna do big year menu because this particular sheet is called Big Year. It's a template giveaway for free, and I want the big year menu to be there that it's super custom right now. We can add item now just for. Viewing sake, I'm gonna put this on a new line, but this dot add item does actually go here and you can put it either on a new line or at the end. And now in these parentheses, there's going to be two things. I'm gonna put quotes here, comma quotes. The very first thing is what users see. So I'm gonna say big thumbs up, go to better sheets.co.
And I'm gonna put in the second quotes, the function that's going to run when someone clicks that. So we're gonna call this open, better sheets, actually not open, but go to better sheets. And very important at the end, we do add to ui. That is all we need for our menu to exist. However, we need this function to exist as well. Or we're gonna get an error . So I'm gonna go underneath this error . Underneath all of this is closed, this open. Parentheses. Parentheses. I'm gonna write a new function , go to better sheets with parentheses, with curly brackets, and I'm gonna do something here before I write that script, I'm gonna save. And I wanna just show you that this works, this on open.
So I'm gonna close app script and I'm gonna go back to my sheet and I'm gonna refresh it or close it and open it again so that that on open actually triggers. I haven't done anything else. I haven't added any triggers. That is it. I've just added that text and look up here. You can see big year menu exists. If I click it, it has go to Better Sheets Code. Now nothing's gonna happen. Actually, it probably will gimme an error if I try to. Oh, it just does nothing there. No error at all. Just does nothing. Well, let's go to Extensions app script and actually do something so inside of this function , go to better sheets. We need some HTML variable, HTML equals and we're going to HTML service dot create HTML output. And right here we're gonna write some HTML.
So in. Paragraph P slash p. To end it, we're going to have an A HRIF equals something, so we need double quotes there and that and then slash A, so this is a little bit of HTML code that says just a paragraph, but inside that paragraph, put a link a. To HF, which is just, which reference are we going to? What website are we going to and right be in here in the a. I am gonna put some text click to go to to go to better sheets.co and the HF is gonna be https better sheets.co. I'm gonna add one extra thing, which is a target. Equals in quotes, blank. So now this will just show me a little bit of text that says,
click to go to better sheet.co. And then it'll gimme a link to go. So I'm gonna save this command S or you can click this Save Project to Drive button Next to run. I'm gonna go back to my sheet and remember I already opened the sheet again, so I have this menu and it says, go to better sheets. I'm gonna click it, and nothing happened. Oh, that's because we've only created the HTML. We actually need to set some actually create, show it. So spreadsheet app, get UI show modal dialogue. HTML is our variable, and we'll have a title of it, let's say better sheets. So this HTML variable is right here. We wanna set a width as well. Set width. We can change this later, say 300, and we're gonna set height 100.
Let's see what that looks like. Save it all. Go back to our sheet Big. Your menu. Go to better sheets.co. Oh, I do need to authorize. And every time, or not every time, but the first time somebody uses this. They will need to authorize it. Yes, we can get around that with a little simple thing. Here's better sheets. Click to go to better sheets. Click And there I am@bettersheets.co. Super. Awesome. Right, but let's add one more item to here. 'cause maybe they don't want to go to better sheets yet. Maybe they just wanna find out about it. So add item about better sheets and. I change that there and call this about and write another function about, and here we don't want to go to another page, just we wanna show some alert
or show this modal dialogue, right? We can set yes, HTML in here and write something that looks pretty cool. So we'll have HTML here. Let's make it a little bit bigger set. Get the UI again. Show modal dialogue, HTML, and this title will be about better sheets. I'm not gonna bore you with this. HTML. We are gonna create another variable here, HML content and in back ticks, we're gonna write this. So we've written some HTML here, but we wanna see what it looks like. We have this function called about. It's, we've added this item. If we go back to our sheet and we look at our big year menu, we don't have it yet, so make sure you save and refresh again so that it opens that that unopened trigger triggers. Now we have about better sheets,
and here we have a little bit about better sheets. We can also visit it from here or write some more text here. We can close this as well. So hopefully that gives you a really beginner insight into this custom menu , creating some simple automations that help people see what your sheet is about or see what your company is about. If you're giving away sheets like I am, if you wanna learn more about automations, check out my Udemy course. I'll put a link in the description. It's called Master Spreadsheet Automation. Just in three hours, we go through some pretty awesome things that you can do with automations and with app script over at Extensions app script , and it's app script is in every single Google sheet. So just make better sheets, right? Let's go. 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.