Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Mit Scripts können bestimmte Google-Produkte erweitert werden, indem Benutzeroberflächenelemente hinzugefügt werden, die beim Klicken eine Apps Script-Funktion ausführen. Das häufigste Beispiel ist das Ausführen eines Skripts über ein benutzerdefiniertes Menüelement in Google Docs, Google Sheets, Google Präsentationen oder Google Formulare. Skriptfunktionen können aber auch durch Klicken auf Bilder und Zeichnungen in Google Sheets ausgelöst werden.
Benutzerdefinierte Menüs in Google Docs, Google Sheets, Google Präsentationen oder Google Formulare
Mit Apps Script können Sie in Google Docs, Google Sheets, Google Präsentationen oder Google Formulare neue Menüs hinzufügen, wobei jedes Menüelement mit einer Funktion in einem Skript verknüpft ist. In Google Formulare sind benutzerdefinierte Menüs nur für Bearbeiter sichtbar, die das Formular zum Bearbeiten öffnen, nicht für Nutzer, die das Formular zum Beantworten öffnen.
Im folgenden Beispiel wird gezeigt, wie Sie ein Menü mit einem Element, gefolgt von einem visuellen Trennzeichen und dann einem Untermenü mit einem weiteren Element hinzufügen. Hinweis: In Google Tabellen müssen Sie, sofern Sie nicht die neue Version verwenden, die Syntax addMenu() verwenden. Untermenüs sind nicht möglich. Wenn der Nutzer eines der beiden Menüelemente auswählt, wird mit einer entsprechenden Funktion ein Benachrichtigungsdialogfeld geöffnet. Weitere Informationen zu den Arten von Dialogfeldern, die Sie öffnen können, finden Sie im Leitfaden zu Dialogfeldern und Seitenleisten.
functiononOpen(){varui=SpreadsheetApp.getUi();//OrDocumentApp,SlidesApporFormApp.ui.createMenu('Custom Menu').addItem('First item','menuItem1').addSeparator().addSubMenu(ui.createMenu('Sub-menu').addItem('Second item','menuItem2')).addToUi();}functionmenuItem1(){SpreadsheetApp.getUi()//OrDocumentApp,SlidesApporFormApp..alert('You clicked the first menu item!');}functionmenuItem2(){SpreadsheetApp.getUi()//OrDocumentApp,SlidesApporFormApp..alert('You clicked the second menu item!');}
Ein Dokument, eine Tabelle, eine Präsentation oder ein Formular kann nur ein Menü mit einem bestimmten Namen enthalten. Wenn dasselbe oder ein anderes Skript ein Menü mit demselben Namen hinzufügt, wird das alte Menü durch das neue ersetzt. Menüs können nicht entfernt werden, während die Datei geöffnet ist. Sie können jedoch Ihre onOpen()-Funktion so schreiben, dass das Menü in Zukunft übersprungen wird, wenn eine bestimmte Property festgelegt ist.
Anklickbare Bilder und Zeichnungen in Google Sheets
Sie können auch eine Apps Script-Funktion einem Bild oder einer Zeichnung in Google Tabellen zuweisen, sofern das Skript an die Tabelle gebunden ist. Das folgende Beispiel zeigt, wie Sie das einrichten.
Wählen Sie in Google Tabellen das Menüelement Erweiterungen>Apps Script aus, um ein an die Tabelle gebundenes Skript zu erstellen.
Löschen Sie jeglichen Code im Skripteditor und fügen Sie den unten angegebenen Code ein.
function showMessageBox() {
Browser.msgBox('You clicked it!');
}
Kehren Sie zu Google Sheets zurück und fügen Sie ein Bild oder eine Zeichnung ein, indem Sie Einfügen > Bild oder Einfügen > Zeichnung auswählen.
Klicken Sie nach dem Einfügen des Bilds oder der Zeichnung darauf. Oben rechts wird ein kleines Drop-down-Menü angezeigt. Klicken Sie darauf und wählen Sie Skript zuweisen aus.
Geben Sie im angezeigten Dialogfeld den Namen der Apps Script-Funktion ein, die Sie ausführen möchten, ohne Klammern – in diesem Fall showMessageBox.
Klicken Sie auf OK.
Klicken Sie noch einmal auf das Bild oder die Zeichnung. Die Funktion wird jetzt ausgeführt.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Benötigte Informationen nicht gefunden","missingTheInformationINeed","thumb-down"],["Zu umständlich/zu viele Schritte","tooComplicatedTooManySteps","thumb-down"],["Nicht mehr aktuell","outOfDate","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Problem mit Beispielen/Code","samplesCodeIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-08-31 (UTC)."],[[["\u003cp\u003eApps Script allows you to extend Google products like Docs, Sheets, Slides, and Forms by adding custom menus and clickable elements that trigger script functions.\u003c/p\u003e\n"],["\u003cp\u003eCustom menus can be created within these Google products, with each menu item linked to a specific function in your script, enhancing user interaction and functionality.\u003c/p\u003e\n"],["\u003cp\u003eIn Google Sheets, you can assign Apps Script functions to images and drawings, making them interactive elements that execute code when clicked in a web browser.\u003c/p\u003e\n"]]],[],null,["# Custom Menus in Google Workspace\n\nScripts can extend certain Google products by adding user-interface elements\nthat, when clicked, execute an Apps Script function. The most common example is\nrunning a script from a custom menu item in Google Docs, Sheets, Slides,\nor Forms, but script functions can also be triggered by clicking on images and\ndrawings in Google Sheets.\n\nCustom menus in Google Docs, Sheets, Slides, or Forms\n-----------------------------------------------------\n\nApps Script can add new menus in Google Docs, Sheets, Slides,\nor Forms, with\neach menu item tied to a function in a script. (In Google Forms, custom menus\nare visible only to an editor who opens the form to modify it, not to a user who\nopens the form to respond.)\n\nA script can only create a menu if it is\n[bound](/apps-script/scripts_containers) to the document, spreadsheet, or form.\nTo display the menu when the user opens a file, write the menu code within an\n[`onOpen()`](/apps-script/understanding_triggers) function.\n\nThe example below shows how to add a [menu](/apps-script/reference/base/menu)\nwith one item, followed by a\n[visual separator](/apps-script/reference/base/menu#addSeparator()), then a\n[sub-menu](/apps-script/reference/base/menu#addSubMenu(Menu)) that contains\nanother item. (Note that in Google Sheets, unless you're using the\n[new version](https://support.google.com/drive/answer/3541068), you must use the\n[`addMenu()`](/apps-script/reference/spreadsheet/spreadsheet#addMenu(String,Object))\nsyntax instead, and sub-menus are not possible.) When the user selects either\nmenu item, a corresponding function opens an\n[alert](/apps-script/reference/base/ui#alert(String)) dialog. For more\ninformation on the types of dialogs you can open, see the\n[guide to dialogs and sidebars](/apps-script/guides/dialogs). \n\n function onOpen() {\n var ui = SpreadsheetApp.getUi();\n // Or DocumentApp, SlidesApp or FormApp.\n ui.createMenu('Custom Menu')\n .addItem('First item', 'menuItem1')\n .addSeparator()\n .addSubMenu(ui.createMenu('Sub-menu')\n .addItem('Second item', 'menuItem2'))\n .addToUi();\n }\n\n function menuItem1() {\n SpreadsheetApp.getUi() // Or DocumentApp, SlidesApp or FormApp.\n .alert('You clicked the first menu item!');\n }\n\n function menuItem2() {\n SpreadsheetApp.getUi() // Or DocumentApp, SlidesApp or FormApp.\n .alert('You clicked the second menu item!');\n }\n\nA document, spreadsheet, presentation, or form can only contain one menu with\na given name. If the same script or another script adds a menu with the same\nname, the new menu replaces the old. Menus cannot be removed while the file\nis open, although you can write your `onOpen()` function to skip the menu in\nthe future if a certain [property](/apps-script/guides/properties) is set.\n| **Note:** [Editor add-ons](/workspace/add-ons/concepts/types#editor_add-ons) can have menu items as well, but use [special rules](/workspace/add-ons/concepts/menus) they are defined.\n\nClickable images and drawings in Google Sheets\n----------------------------------------------\n\nYou can also assign an Apps Script function to an image or drawing in Google Sheets,\nso long as the script is [bound](/apps-script/scripts_containers) to the\nspreadsheet. The example below shows how to set this up.\n\n1. In Google Sheets, select the menu item **Extensions** \\\u003e **Apps Script** to create a script that is bound to the spreadsheet.\n2. Delete any code in the script editor and paste in the code below.\n\n function showMessageBox() {\n Browser.msgBox('You clicked it!');\n }\n\n3. Return to Sheets and insert an image or drawing by selecting\n **Insert \\\u003e Image** or **Insert \\\u003e Drawing**.\n\n4. After inserting the image or drawing, click it. A small drop-down menu\n selector appears in the top right-hand corner. Click it and choose\n **Assign script**.\n\n5. In the dialog box that appears, type the name of the Apps Script function\n that you want to run, without parentheses --- in this case, `showMessageBox`.\n Click **OK**.\n\n6. Click the image or drawing again. The function now executes.\n\n| **Note:** The script execution is only triggered by clicking the image or drawing in a web browser. The script doesn't execute if the image or drawing is clicked on mobile."]]