Google Apps Script in Sheets Menus
If you are using Google Apps Script to process data in a Google Sheet, then you may want a menu loaded as part of the sheet, so you don't have to open the Apps Script interface, choose the proper funtion from the drop-down, and then hit run. This short snippet inside your Apps Script will allow you to create a menu item that runs a specific function.
function onOpen() {
// Create the menu on the spreadsheet
var ui = SpreadsheetApp.getUi();
ui.createMenu('Menu Header Text')
.addItem('Menu Item A', 'functionA')
.addItem('Menu Item B', 'functionB')
.addItem('Menu Item C', 'functionC')
.addSubMenu(ui.createMenu('Sub-Menu-Text')
.addItem('Sub Menu - Item A', 'functionSubA')
.addItem('Sub Menu - Item A', 'functionSubA')
.addItem('Query Departed Date (Column D)', 'getDepartedDate'))
.addToUi();
}
functionA () {
# Do something
}
functionB () {
# Do something
}
etc...
Now when you open the sheet you will see the menu appear. Choosing the menu option will run the associated function listed with that option.