What is the onOpen trigger in Google Sheets?

The onOpen trigger runs an Apps Script function automatically when someone opens the spreadsheet. It is the standard way to add custom menus, show instructions, or refresh lightweight cache without asking the user to run a macro first. Name the function onOpen or bind it as an installable open trigger.

When to use it

Use onOpen to register a custom menu, set up sidebar launchers, warm a small config range, or show a one-time welcome note for editors. It sets the stage before anyone clicks Run.

When to skip it

Skip onOpen for heavy imports, bulk API syncs, or anything that must run while the file is closed. Users notice slow opens. Use time-driven triggers or a manual menu item for long jobs.

How it works

  1. 1

    Create a function named onOpen in Apps Script (capital O is required for the simple trigger).

  2. 2

    Inside onOpen, call SpreadsheetApp.getUi().createMenu() to add items that call other functions.

  3. 3

    Save the project and reload the spreadsheet to test; the menu appears after the sheet finishes opening.

  4. 4

    {:"Keep onOpen fast"=>"defer real work to functions the user chooses from the menu."}

  5. 5

    For stricter permissions, add an installable onOpen trigger from the Triggers page in Apps Script.

  6. 6

    Document menu labels so teammates know which action is safe on production data.

Examples in Google Sheets

Custom "Better Sheets tools" menu

onOpen adds menu items like "Refresh dashboard" and "Email weekly summary" that call named functions when clicked.

Show setup checklist once

onOpen reads a hidden Settings cell; if blank, sets a friendly note in A1 reminding editors to pick their region from a dropdown.

Sidebar launcher

A menu item calls showSidebar() which opens HtmlService UI for a form that writes to the sheet.

Build this without starting from a blank cell

Use a Better Sheets tool for onOpen trigger, then watch a walkthrough when you want the full pattern.

Better Sheets resources

Common mistakes

  • Naming the function onopen with lowercase o, so the simple trigger never fires.
  • Running a five-minute sync inside onOpen, which makes every open feel broken.
  • Assuming onOpen runs for viewers; viewers often cannot run scripts that need edit access.
  • Forgetting to authorize the script once as an editor before expecting menus for the whole team.
  • Creating duplicate menus on every open without checking if the menu already exists (rare but confusing in tests).

Frequently asked questions

Does onOpen run for viewers?
View-only users may not get custom menus or full script behavior. Test with the same role your audience has.
onOpen vs installable open trigger?
Simple onOpen is easy but limited. Installable open triggers can run with broader authorization when configured.
Can onOpen modify data automatically?
It can, but automatic writes on every open surprise users. Prefer menus for destructive actions.
Why is my menu missing?
Check the function name, script errors in Executions, and whether you are in a copy that lost the bound script.
Does onOpen run on mobile?
Mobile Sheets has limited Apps Script UI support. Do not rely on custom menus for mobile-only workflows.
Can onOpen open a sidebar automatically?
You can, but auto sidebars annoy power users. A menu item is usually better UX.
How do I debug onOpen?
Add Logger.log at the top, reload the file, then view Executions in Apps Script.
Is onOpen the same as opening a web app?
No. onOpen is tied to the spreadsheet UI. Web apps use doGet and their own URL.

Related Tutorials

Watch how onOpen trigger works

Browse more tutorials
Activate A Certain Sheet When Opening a Spreadsheet

Activate A Certain Sheet When Opening a Spreadsheet

Create a short function that runs every time a spreadsheet file is open....
What Can You Automate in Google Sheets? Every single trigger available to Google Sheet users

What Can You Automate in Google Sheets? Every single trigger available to Google Sheet users

Learn about triggers, hourly, daily, weekly, etc.
Spreadsheet Automation 101 Lesson 1: onOpen() Trigger - Custom Menu

Spreadsheet Automation 101 Lesson 1: onOpen() Trigger - Custom Menu

This lesson will get you started on your first trigger. It’s the first r...
OnInstall to onOpen

OnInstall to onOpen

We need to bridge the gap between an add-on not being installed to actua...
Add-on menu on open

Add-on menu on open

Instead of just adding a custom menu to a sheet, we're going to turn thi...
Open Spreadsheet to Motivational Quote Automatically

Open Spreadsheet to Motivational Quote Automatically

Create a simple script to open a particular tab. In this case we're open...

Related blog posts

Guides that explain onOpen trigger in more depth.

Browse the blog

Related glossary terms

Done reading about onOpen trigger?

Membership unlocks 636+ tutorials, unlimited generators, and every template. Practical lessons. Zero fluff.

Need this once

Jump to a free tool or a single tutorial for this topic.

Learning Sheets for real

Unlock the full library, generators, and templates with membership.