How To Display a Message in Google Documents and Spreadsheets

Share This:

Letting an end user know when something has finished running is very important. It gives them a visual clue that the process has completed so they aren’t sitting there guessing or trying to run the process again. Let’s learn how to display a message to an end user in both a Google Document and Spreadsheet!

Display a Message in Google Spreadsheets

How To Display a Message in Google Documents and Spreadsheets

Let’s say that the end user selected an option from a custom menu which runs a function. When that function finishes, it would be nice to tell the user that it has completed. It’s as simple as adding the following to the end of your function:

SpreadsheetApp.getActiveSpreadsheet().toast("My message to the end user.","Message Title");

Let’s explain that little piece of code:

  1. The message will display in the bottom right hand corner of whichever sheet is currently active.
  2. The first parameter is the actual text of the message.
  3. The second parameter is the title of the message.
  4. The message will only be visible for 5 seconds.

Simple right! But 5 seconds may be a bit too quick for an end user to finish reading the message. Can we make it display longer? Yes we can! Use the following:

SpreadsheetApp.getActiveSpreadsheet().toast("My message to the end user.","Message Title",15);

The third parameter represents the number of seconds you would like the message to be visible. Would you prefer to force the end user to close the message instead? That can done as well! Use the following:

SpreadsheetApp.getActiveSpreadsheet().toast("My message to the end user.","Message Title",-1);

Again, the use of the third parameter comes into play, but this time it’s a negative number. The number itself doesn’t matter, just as long as it’s negative.

Display a Message in Google Documents

How To Display a Message in Google Documents and Spreadsheets

Displaying a message in a Google Document is a little different from a Spreadsheet in terms of the code, which is the following:

DocumentApp.getUi().alert("Message Title","My message to the end user.",DocumentApp.getUi().ButtonSet.OK);

Let’s explain that little piece of code:

  1. We use the document’s user interface to display an alert, which will display in the center of the document.
  2. The first parameter is the message title.
  3. The second parameter is the actual text of the message.
  4. The third parameter is the type of button set we want to display, which in this case a simple Ok button will do.

You now know how to display a helpful message to an end user in both Google Documents and Spreadsheets!

Share This:

Related Tutorials