7
votes

I want to display a message on a google sheet. But I don't get it, and, after research here, in documentation, I don't get the answer.

I think that the problem is in "activate" the spreadsheet, where i need to display.

var SEGUIMIENTO = SpreadsheetApp.openById("MyTestediD");
var INF = SEGUIMIENTO.getSheetByName("NameOfSheet");
function TestMessage() {
  INF.activate();
  Browser.msgBox("Hello")
}

When i run.. nothing happen

I need the definition of Spreadsheet outside the function because I'm working in 2 Spreadsheet's by ID in more that one function.

i only need the correction in my code for display a simple message in the spreadsheet.

PD. i really cant find a simple example of that,

Update

This code it's part of a macro recorder of a Spreadsheet, the same "SpreadsheetApp.openById("MyTestediD");"

3
Welcome. The information about your case is incomplete. Is this code included on a bounded script or on a standalone script?Rubén

3 Answers

17
votes

I don't know why you try to 'activate' a sheet. If you want display a message I assume you want to do it in the user's current sheet, so:

SpreadsheetApp.getUi().alert('Confirmation received.');
0
votes

From https://developers.google.com/apps-script/reference/base/browser

The methods in this class are only available for use in the context of a Google Spreadsheet. Please use G Suite dialogs instead.

As you can see, Google is nicely asking you to use G Suite dialogs instead of Class Browser, so be nice too and follow their request.

0
votes

When you say you want a message in a spreeadsheet, do you mean an alert message? If so, the answer is to use the code SpreadsheetApp.getUi().alert('Hello.'); when the TestMessage function is executed

var SEGUIMIENTO = SpreadsheetApp.openById("My TestediD");
var INF = SEGUIMIENTO.getSheetByName("NameOfSheet");
function TestMessage() {
  INF.activate();
  SpreadsheetApp.getUi().alert('Hello.');
}