Google Apps Script menu function not executing when clicked from custom spreadsheet menu

I’m having trouble getting my custom menu in Google Sheets to actually run the function when I click on it. I created a simple setup but when I click the menu item, nothing happens or I get an error.

Here’s what I have:

function executeTask(){
  console.log("Task executed");
}

function setupCustomMenu() {
   var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
   var options = [];
   options.push({name: "Run Task", functionName: "executeTask"});

   spreadsheet.addMenu("Custom Tools", options);
}

The menu shows up fine in my spreadsheet, but clicking on “Run Task” doesn’t seem to trigger the executeTask function. I’m not sure if I’m missing some step or if there’s something wrong with my code setup. Any ideas what could be going wrong here?

This is probably a permissions issue. Google Apps Script needs authorization before custom menu functions can run properly. Go to the Apps Script editor and run executeTask directly first - this’ll authorize it. Also, ditch console.log since you won’t see it from the menu anyway. Use SpreadsheetApp.getUi().alert(“Task executed”) instead to confirm it’s working. Check the execution transcript in Apps Script after clicking your menu item too - the function might be failing silently and you’d see any errors there.

you need an onOpen trigger so the menu shows up when the sheet loads. add function onOpen() { setupCustomMenu(); } to your code. also make sure your executeTask function is actually saved.

Had this exact problem a few months back - drove me crazy for hours. Your setupCustomMenu function probably isn’t running automatically. Try running it manually from the script editor or set up proper triggers. Here’s what others missed though - check if you’ve got multiple script versions saved. Sometimes Sheets references an old version where your function doesn’t exist or has a different name. Also make sure executeTask is spelled exactly the same in both places (case matters). One more thing - if it’s a shared spreadsheet, you need edit permissions, not just view access. Custom menus won’t work otherwise.