0

I'm new to scripting and have been trying to get this URL shortener script to show in my spreadsheet. I have clicked 'debug' to authenticate the script, then what?

I thought the menu item would be created in the Google Sheet... what am I missing please? I'm sure it's pretty basic!

Editor notes: The same applies to spreadsheets, documents, forms and presentations of the nowadays named by Google as G Suite document editors.

0

1 Answer 1

1

If you want to add something to a menu, you need to implement an onOpen function, and do the necessary menu setup there.

Take a look at this example from Google's documentation:

function onOpen() {
  // Add a custom menu to the spreadsheet.
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
      .createMenu('Custom Menu')
      .addItem('First item', 'menuItem1')
      .addToUi();
}

This will add a menu Custom Menu with a single item First item, which, when selected, will launch a function menuItem1, which you will have to implement:

function menuItem1() {
  // Do whatever you like here
}

Note that you will have to reload your file ( spreadsheet, document, form or presentation ) in order to have onOpen run. So you won't see any effect by just writing the script and clicking save, you need to reload (Cmd-R) on the file window for the new menu to appear.

A script error may prevent the menu from appearing. If you don't see the desired result after reloading the file, check the script editor's View → Execution Transcript for any errors.

1
  • Thanks, Vidar, I'll give that a go today! Appreciate the help greatly.
    – Rob Clarke
    Commented Nov 14, 2017 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.