Create Custom Menus

To create a custom menu in Apps Script, follow these steps:

  1. Open your Google Sheets document and navigate to “Tools” in the top menu bar.
  2. Select “Script editor” to open the Google Apps Script editor.
  3. In the editor, click on “File” and select “New” > “Script file”.
  4. Name your new script file and click “OK”.
  5. Add the code to create a custom menu using the class in the new script file
function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Custom Menu')
      .addItem('Menu Item 1', 'menuItem1')
      .addItem('Menu Item 2', 'menuItem2')
      .addSeparator()
      .addItem('Menu Item 3', 'menuItem3')
      .addToUi();
}

function menuItem1() {
  // Code to run when Menu Item 1 is selected
}

function menuItem2() {
  // Code to run when Menu Item 2 is selected
}

function menuItem3() {
  // Code to run when Menu Item 3 is selected
}
  1. Save the script by clicking “File” > “Save”.
  2. Return to your Google Sheets document and refresh the page. You should now see your custom menu in the top menu bar.

In this example, the onOpen() the function creates a custom menu with three menu items and a separator. Each menu item is linked to a separate function that will be called when the item is selected. You can customize the menu items and their associated functions to meet your specific needs.