Join Scott Simpson for an in-depth discussion in this video Creating a menu, part of Up and Running with Google Apps Script.
- View Offline
- We've seen how to set up time triggers,…so now let's take a look at behavior-driven triggers.…We'll use the onOpen function to add…a custom menu to a spreadsheet.…The behavioral triggers rely on protected function names…and will be run whenever the event they refer to fires.…You can see a complete list in the documentation,…but I find onOpen and onEdit…to be the most useful day to day.…To take advantage of the onOpen trigger,…I'll just create a new function called onOpen.…
The e value being passed in here…is the onOpen event object itself,…which needs to be handled by the function.…We're not using it here, but it's available…for more advanced uses if need be.…In order to interact with the user interface…of the spreadsheet, I need to call the…SpreadsheetApp.getUi method.…I'll write SpreadsheetApp.getUi,…and then I'll use the createAddonMenu method,…and I'll add an item to it with the additem method.…
You can see you can also add separators and submenus…to organize your menu further.…For the caption, I'll say "Add some text",…
First, learn how to use simple scripts to edit documents and spreadsheets, work with files in Drive, and find and send messages in Gmail. Then find out how to add custom functionality to your spreadsheets, and build user interface elements for your scripts, using menus, alerts, and dialogs. Finally, Scott shows how to share your work with others by publishing scripts as web apps.
- What is Google Apps Script?
- Understanding script types
- Logging and debugging your scripts
- Scripting common tasks
- Building custom spreadsheet functions
- Creating add-on functionality such as dialogs and sidebars
- Sharing your script as a web app