In this video, you will add a custom menu to Google Sheets.
A user will click on this menu to access your Auto Editor, and the submenu
to run your Auto Editor program in the document.
To start, add a function called "onOpen" to your program.
Beneath the “highlightProblem” function, type “function,” space, “onOpen,”
exactly as you see here.
End the function with a closed curly brace.
Code inside an "OnOpen" function runs as soon as the document opens.
Use the DocumentApp "Get UI" function to set the values for your custom menu.
Then, type “.createMenu.”
Use the autofill menus to help.
Next, name the custom menu and submenu anything you like.
The “caption” you type here is the title of the custom menu in the Google Docs toolbar.
Put the title in single quotes.
Next, type “.addItem” and change the parameters.
The first parameter is the title of the submenu.
The second parameter is the “highlightProblem” function.
Enclose both of these parameters with single quotes.
Finally, type “.addToUi” to add the menu to the Google Docs toolbar.
A custom menu is a common feature for programmers to add in Apps Script.
If you search the internet or the API Reference, you will find more information and examples.
Save your code and try it out.
Remove all the highlighting from your document.
Then, refresh the page.
When you open the document, the menu appears.
The submenu appears.
Now, click the submenu to run the program.
Now all of the overused words are highlighted!
Go back to your code, and add a comment about what this function does.
In the next activity, you will highlight each word with a different color
to make it easier to recognize.
Now it's your turn.
Add a custom menu that makes it easy to run your program from the document.