2
votes

I am trying to add a menu in the onOpen function. But it is not firing. Below is my code.

  function onOpen() {
  var sheet = SpreadsheetApp.getActiveSheet(); 
  var options = [{name:"Send", functionName:"sendAll"}];
  sheet.addMenu("SMS", options);
  }

When I try to run the function in debug, it shows the error.

Can not find addMenu in the object sheet.

How to fix this.

1

1 Answers

0
votes

You're trying to use some Menu method on Sheet class. Take a look at the class Menu documentation:

// Add a custom menu to the active spreadsheet, including a separator and a sub-menu.
 function onOpen(e) {
   SpreadsheetApp.getUi()
       .createMenu('My Menu')
       .addItem('My Menu Item', 'myFunction')
       .addSeparator()
       .addSubMenu(SpreadsheetApp.getUi().createMenu('My Submenu')
           .addItem('One Submenu Item', 'mySecondFunction')
           .addItem('Another Submenu Item', 'myThirdFunction'))
       .addToUi();
 }