I’m trying to make a popup message appear in my Google Sheet using Apps Script. I’ve been looking everywhere but can’t figure it out. Here’s what I’ve tried:
const mySheet = SpreadsheetApp.openById('12345abcde');
const dataTab = mySheet.getSheetByName('DataSheet');
function showPopup() {
dataTab.activate();
Browser.msgBox('Hey there!');
}
When I run this, nothing happens. I need to keep the spreadsheet stuff outside the function because I’m working with multiple sheets in different functions.
Can someone help me fix this code to show a simple message? I’m using a macro recorder in the spreadsheet if that matters.
I just need a basic example to get this working. Thanks!
Hey there! I’ve dealt with this exact issue before. The problem is that Browser.msgBox() doesn’t work when you’re running the script from the script editor. It only shows up when the script is triggered from the spreadsheet itself.
Here’s a workaround I use:
Instead of Browser.msgBox(), try using SpreadsheetApp.getUi().alert(). This should work regardless of how you’re running the script.
So your function would look like this:
function showPopup() {
dataTab.activate();
SpreadsheetApp.getUi().alert('Hey there!');
}
Make sure you’re running this function from a button or menu item in your spreadsheet, not directly from the script editor. That should do the trick!
Also, if you’re using a macro recorder, remember that some actions might not translate perfectly to code. Sometimes you need to tweak things a bit to get them working properly.
i’ve run into this too! the trick is to use SpreadsheetApp.getUi().alert() instead of Browser.msgBox(). it works better with apps script. just change ur function to:
function showPopup() {
dataTab.activate();
SpreadsheetApp.getUi().alert('Hey there!');
}
hope that helps! let me know if u need anything else
I see you’re struggling with popup messages in Google Sheets. Here’s a reliable method I’ve used in my projects:
Instead of Browser.msgBox(), try using SpreadsheetApp.getUi().alert(). This function is more consistent across different execution contexts.
Modify your showPopup() function like this:
function showPopup() {
dataTab.activate();
SpreadsheetApp.getUi().alert(‘Hey there!’);
}
Make sure to run this from a trigger in your spreadsheet, such as a button or custom menu item, rather than directly from the script editor. This approach should resolve your issue and display the popup as expected.
Remember, when using the macro recorder, some actions may require manual adjustments in the code for optimal functionality.