Google Sheets Custom Menu to Open URLs in New Window

Introduction

Google Sheets is more than a simple spreadsheet; it can act as a lightweight dashboard that links directly to external resources. One common request from power users is the ability to open a web page in a new browser window straight from a custom menu inside the sheet. This capability streamlines workflows, reduces context‑switching, and gives teams instant access to documentation, analytics dashboards, or CRM records without leaving the spreadsheet environment. In this tutorial we will walk through the entire process: creating a custom menu, writing a Apps Script function that launches a URL in a new window, attaching the script to the spreadsheet, and finally testing the solution. By the end, you’ll have a reusable menu item that opens any web page with a single click.

Why a Custom Menu?

Standard Google Sheets menus cover basic actions such as formatting, data validation, and file operations. However, they do not provide a direct shortcut for launching external URLs. A custom menu fills this gap by placing a user‑defined command exactly where users expect to find other tools. It also offers:

  • Consistency – the same menu appears for every collaborator, ensuring uniform access.
  • Scalability – you can add multiple links or even dynamic URLs based on sheet data.
  • Security – the script runs under your account’s permissions, avoiding the need for users to copy‑paste links manually.

Setting Up the Script Editor

To begin, open the spreadsheet where you want the menu. From the top bar choose Extensions → Apps Script. This opens the integrated development environment (IDE) where you will write the JavaScript‑based code. The IDE creates a default Code.gs file; you can keep this name or create a new one for clarity. Ensure you are working in the .gs file, not a HTML file, because the function that opens the URL will be a server‑side script.

Writing the Function to Open a New Window

The core of the solution is a simple function that uses the SpreadsheetApp.getUi() object to call showModalDialog with a tiny HTML snippet. The HTML contains a window.open call that targets “_blank”, forcing the browser to open a new tab or window. Example code:

  • function openInNewWindow() {
  •   var url = ‘https://www.example.com’; // replace with your target
  •   var html = ‘<script>window.open(“‘ + url + ‘”, “_blank”);google.script.host.close();</script>’;
  •   var userInterface = HtmlService.createHtmlOutput(html);
  •   SpreadsheetApp.getUi().showModalDialog(userInterface, ‘Opening…’);
  • }

This script builds a temporary dialog that immediately triggers the browser to open the desired page, then closes itself. You can modify the url variable to read a cell value, allowing dynamic links based on sheet content.

Adding the Menu to the Spreadsheet

With the opening function ready, you need to expose it through a custom menu. Add a second function called onOpen – Google Sheets automatically runs this each time the file is opened.

  • function onOpen() {
  •   var ui = SpreadsheetApp.getUi();
  •   ui.createMenu(‘Quick Links’)
  •     .addItem(‘Open Example Site’, ‘openInNewWindow’)
  •     .addToUi();
  • }

When the spreadsheet reloads, a new top‑level menu named “Quick Links” appears, containing the “Open Example Site” command. Clicking it triggers openInNewWindow, launching the page in a fresh window.

Testing and Troubleshooting

Save the script (⌘ S / Ctrl S) and return to the spreadsheet. Reload the sheet to fire onOpen. If the custom menu does not show, verify that the script is bound to the correct spreadsheet and that you have authorized the script to run under Run → Run function → onOpen. The first execution will prompt an authorization dialog; accept the required scopes. If the URL fails to open, check the console for errors – common issues include missing “https://” in the URL or browser popup blockers. Adjust the window.open parameters if you need the link to open in a new tab instead of a separate window.

Conclusion

By leveraging Google Apps Script, you can transform a plain Google Sheet into an interactive hub that launches external web pages with a single menu click. The process starts with creating a custom menu, continues with a concise function that uses a modal dialog to trigger window.open, and finishes with testing and fine‑tuning the script for reliability. This approach not only saves time but also standardizes access to critical resources across your team. Once you master the basic example, you can extend it to read URLs from cells, generate dynamic dashboards, or integrate with other Google Workspace services, turning your spreadsheet into a powerful, centralized command center.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Digital Malayali