Home > Net >  I'm trying to write a custom menu for Google Sheets but It's not showing up
I'm trying to write a custom menu for Google Sheets but It's not showing up

Time:02-20

My code is below. I have tried refresh and re opening the sheet to no avail. I own and have full editing permissions on the sheet so I'm not sure why this doesn't work. Any help appreciated

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Custom Menu')
      .addItem('First item', 'menuItem1')
      .addSeparator()
      .addSubMenu(ui.createMenu('Sub-menu')
          .addItem('Second item', 'menuItem2'))
      .addToUi();
}

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

function menuItem2() {
  SpreadsheetApp.getUi() 
     .alert('You clicked the second menu item!');
}

CodePudding user response:

Hey I have just copy/paste your code. I also saved it and executed it. The custom menu appeared immediately.

After saving it did you execute it by any change? You need to click here

enter image description here

CodePudding user response:

You need to confirm that the file saved correctly and the necessary permissions have been granted to the script (not just the user edit access permission).
This script you have here works just fine.

  • Related