Custom menu items can enhance user experience. Here’s how to add one:
Step-by-Step Guide:
- Open the Script Editor:
- Navigate to
Extensions > Apps Script
.
- Navigate to
- Write the Menu Script:
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu(‘Custom Menu’)
.addItem(‘Show Alert’, ‘showAlert’)
.addToUi();
}
function showAlert() {
SpreadsheetApp.getUi().alert(‘Hello, world!’);
}
- Refresh the Sheet:
- Reload your Google Sheet to see the new menu.
Explanation:
- onOpen Trigger: Adds a custom menu when the sheet is opened.
- Menu Item: Adds an item that triggers the
showAlert
function.