Members-only tutorial
Watch the video and get the practice sheet with membership.
About this Tutorial
Sheet Resources
Video Transcript
<div>0:00 So there's something that happens in BetterSheets and when members ask me questions, or non-members sometimes, ask me questions, ah, sometimes I don't know the answer.<br>0:10 For instance, someone might ask, if a tab name is changed, how do I get an alert for that? How can I create some kind of alert system if someone in my organization changes the name of the tab?<br>0:23 Can I do that? And the answer is I don't know.
But what I'm going to show you here is me experimenting with it.<br>0:29 So at the moment I literally don't know if this is possible, but we're going to do an experiment with Apps Script Learn about Apps Script and how it can automate tasks in Google Sheets. Opens in new tab because I do know that there is an on-edit simple trigger Discover what simple triggers are and how they work in Google Sheets. Opens in new tab we can use.<br>0:40 But the edit means the user changes the value of a cell. There is, however, another type of trigger Understand the different types of triggers available in Google Sheets. Opens in new tab where Explore the query where clause for filtering data in Google Sheets. Opens in new tab we can install that trigger Understand the different types of triggers available in Google Sheets. Opens in new tab .<br>0:52 And when we install a trigger Understand the different types of triggers available in Google Sheets. Opens in new tab we can use the on-change. Now on-change means you change the structure of a sheet.<br>0:58 So you add a column, add a sheet Find out how to add a new sheet to your Google Sheets document. Opens in new tab .
It doesn't, in the documentation, include any information about the changing name. So we're going to experiment with that today.<br>1:07 And I'm going to show you this experiment, literally, as I do it, because I have never done this before. And I wanted to show you that this kind of answering of these questions can be very playful and very much just playing around with what it is available, and understanding what is available and trying<br>1:23 new things. So we're going to create a function Get to know functions in Google Sheets and how to use them effectively. Opens in new tab . We're going to say alert me on form, no, tab name change.<br>1:31 Okay.
So this is the thing we want to do. So what we want it to do, let's do something pretty simple first.<br>1:38 spreadsheet Learn about spreadsheets and their features in Google Sheets. Opens in new tab app dot um we want toast, a spreadsheet Learn about spreadsheets and their features in Google Sheets. Opens in new tab toast. We'll just go here, and I always forget how this works.<br>1:48 Get active toast, that's all we need. Spreadsheet Learn about spreadsheets and their features in Google Sheets. Opens in new tab app, get active, and we're going to do toast.
And the message we're going to say is, you've changed the tab name.<br>1:59 So we're You're not even- We're using any variables yet, we're not doing anything crazy, we're just going to check and experiment this.<br>2:07 We're going to save that, we can call this experiment tab name change. And let's see what. The next thing we need to do is actually create the trigger Understand the different types of triggers available in Google Sheets. Opens in new tab for it.<br>2:19 So we'll go over here to triggers. It will need a moment on the bottom right, click add trigger Understand the different types of triggers available in Google Sheets. Opens in new tab , choose which function Get to know functions in Google Sheets and how to use them effectively. Opens in new tab to run.<br>2:26 There is only one function Get to know functions in Google Sheets and how to use them effectively. Opens in new tab , we don't need to change that.
The select Understand the query select clause for selecting data in Google Sheets. Opens in new tab event source is going to be from spreadsheet Learn about spreadsheets and their features in Google Sheets. Opens in new tab and it's this on change.<br>2:34 Again we're experimenting if the tab name is a change. You also have on edit here. But again, that is just editing a value in a cell and not the editing the sheet name Learn how to manage and change sheet names in Google Sheets. Opens in new tab , I think.<br>2:48 But let's see, on change should be it, or if it would include it, so save. Now we can also test this on change in another way.<br>3:00 So actually. we need to authorize these things. Let's authorize it.
I think there's another way we can test this, ah, to show you that this will work.<br>3:10 If it doesn't work, I'll show you that it will work. But let's just save that. OK, now we are triggering any change.<br>3:18 So again, any change meaning, actually, let's be, this is the other way to test it. So we're going to duplicate Discover how to duplicate sheets and data in Google Sheets. Opens in new tab that.<br>3:24 Let's see if we get a, and we have changed. But, OK, the message is just a hard-coded. We haven't actually change the tab name.<br>3:35 But let's go and change this to data2. That is a change of the structure.
And it is, you've changed the tab name.<br>3:45 That is fantastic. So, it works. So now we know definitively that a change in the structure ah, is happening, but also changing the tab name is this onChange, ah, change.<br>4:01 Trigger Understand the different types of triggers available in Google Sheets. Opens in new tab . That is really cool.
And so, let's say you are an organization and you are like hey, I want to know if one of my people has changed this sheet in some way, meaning they've added a tab, they've deleted columns, added columns, they're changing the name, That's all included here.<br>4:23 So this toast is going to show up in the, uh, in the app and in the spreadsheet Learn about spreadsheets and their features in Google Sheets. Opens in new tab . So you've changed something, we should probably say, because it's not so specific.<br>4:34 Also, what we can do here is add a mail app or gmail app. Uh, send email.
And we're going to send an email to, uh, we can probably do the owner Find out how to identify the owner of a Google Sheets document. Opens in new tab , but not the session.<br>4:49 So here in Apps Script Learn about Apps Script and how it can automate tasks in Google Sheets. Opens in new tab we have a get owner Find out how to identify the owner of a Google Sheets document. Opens in new tab , so we can use this app active spreadsheet Learn about the active spreadsheet and how to reference it in scripts. Opens in new tab , get owner Find out how to identify the owner of a Google Sheets document. Opens in new tab , get email here.<br>4:57 so we will send an email to the owner Find out how to identify the owner of a Google Sheets document. Opens in new tab . We can do variable owner Find out how to identify the owner of a Google Sheets document. Opens in new tab equals get owner Find out how to identify the owner of a Google Sheets document. Opens in new tab , get email. There we go.<br>5:10 We're going to send an email and we're going to say hey, uhm, hey something's changed. Uh, and in the body we'll say, uh, check.<br>5:20 out this spreadsheet. And we want to add a URL here.
So we'll get variable URL equals spreadsheet Learn about spreadsheets and their features in Google Sheets. Opens in new tab app dot get active spreadsheet Learn about the active spreadsheet and how to reference it in scripts. Opens in new tab , get URL.<br>5:36 There we go. Uh, and we can also So, let's look at. at this body as it's sent. So variable body equals this.<br>5:46 And then we want to logger dot log body. So we can see it in here. And we'll send that email.<br>5:54 So now we don't have to update the trigger Understand the different types of triggers available in Google Sheets. Opens in new tab the trigger Understand the different types of triggers available in Google Sheets. Opens in new tab will still work we just have to save this and we will go and update something.<br>6:02 So let's duplicate Discover how to duplicate sheets and data in Google Sheets. Opens in new tab this and we can go back into our executions look at the ah we see we failed.
Let's see what we did here.<br>6:15 Ah if we refresh we should be able to get the error Explore common errors in Google Sheets and how to troubleshoot them. Opens in new tab message. Script does not have permission. So, um what I think we need to do is go to the editor Understand the Google Sheets editor and its functionalities. Opens in new tab .<br>6:24 If I just hit run on here I should be able to access the authorization Learn about authorization requirements for Google Sheets scripts. Opens in new tab . There we go. We just have to authorize it again, or not again, one more time with all of these new things in it.<br>6:38 Ah we may get a failure here from the running it in here. But cool. Okay. Let's change something again. Let's change this to data Explore data management techniques in Google Sheets. Opens in new tab three.<br>6:49 Go back to our ah trigger Understand the different types of triggers available in Google Sheets. Opens in new tab , actually execution, sorry. Let's see.
It has completed. Refresh. And this is the body of the email.<br>7:05 And this is what the email looks like over here. It is just check out the spreadsheet Learn about spreadsheets and their features in Google Sheets. Opens in new tab . Something's changed. Ah, there we go.<br>7:12 So this ended up being a pretty interesting dive into emailing upon every change. But it started with the question. Of, can I get an alert every time a tab name is changed?<br>7:25 And the answer is yes. And we can also go much deeper into this and any kind of structural change to the spreadsheet Learn about spreadsheets and their features in Google Sheets. Opens in new tab can be alerted.<br>7:31 Uh, also we can send an email fairly quickly with these alerts.
Hopefully this was pretty helpful and pretty. Very interesting to you because I didn't know the answer to this at the beginning of this and now we went through an experiment.<br>7:46 Eight minutes went by and we are, we know the definitive answer.</div>