Here, if you want to create a button in a Google doc and want to display a message on button click then you need to follow the below steps. We are talking about Google spreadsheets here.
- Now again go to the spreadsheet. We are going to create a button here to display alert message. For this, follow menu Insert -> Object same as below screen.
- This will open a Drawing window from where we can create button. Now follow the steps given in the below screen. It will create a rectangle button. You can drag and name it as "Click Me !" here in our example. Press "Save and Close" button given in below screen, this will create a button.
- Now, once button is created right click on the button and then click on those 3 dots (see the below image). It will open a menu and select the "Assign Script" option from that. It will ask for a script name (i.e function name we have created earlier).
- Here in our example it is "DisplayMsg". You can copy function name from your code.gs file and then paste here.
- All set, now we just need to check this. Click on the "Click Me!" button. It will ask you for the authorization the first time to grant the permission. Google asks this permission for the first time once you follow these steps and run it; the next time it will not ask to authorize app. Click on "Continue" button.
- This will open the below window, click on the "Advanced option" and click on "Go to Button Click Example(unsafe)" option. This option will allow you to run the program.
- Clicking on this option will run the script and display a message like below.
There are many more things we can do with a Google app script. By following all these steps, you have successfully created your first Google app script program.
Please comment or inbox if you have any questions. Thank You!!