Introduction to Using Apps Script With Google Sheets
Accessing Apps Script
Opening Apps Script from your Google Sheets Spreadsheet is as easy as clicking Tools > Script editor.
This creates a script template that is bound to your spreadsheet. Feel free to name your script in the top left corner whatever you would like!
Creating a Function
A function called myFunction is automatically created in the script template upon opening the script editor. In this example, we will add a command within this function that says hello to the spreadsheet user! First things first is getting the spreadsheet user interface and assigning it to a variable. Thankfully, Google’s API makes this easy using the SpreadsheetApp class. Lets go ahead and add the text
var ui = SpreadsheetApp.getUi(); as part of myFunction. Now, adding a dialogue box that says hi to the user is as easy as
Now, go ahead and test your new function by clicking Run > Run function > myFunction. Head back over to your spreadsheet and hopefully you have a hello message!
If this is your first Apps Script function, then congratulations! There will hopefully be plenty more to come :) I hope that this has been a helpful introduction to Apps Script and encourage you to try this on your own! You may find it surprising how quick and easy, but yet very powerful, the scripting language is.
Please check out Part II of this series to see how to prompt the user for information and how to assign a script to a button within the spreadsheet!