Custom menus in Google Sheet Script

The following is used to create custom menus in Google sheet script. The new menus can be quickly used to run the program.


function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Custom Menu1')
.addItem('First item1', 'menuItem11')
.addSeparator()
.addSubMenu(ui.createMenu('Sub-menu1')
.addItem('Second item1', 'menuItem21'))
.addToUi();
}


function menuItem11() {
SpreadsheetApp.getUi() 
.alert('You clicked the first menu item1!');
}


function menuItem21() {
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.alert('You clicked the second menu item1!');
}

 

You must be logged in to post a comment.