How to use the onOpen(e) Function on Google Sheets

In this post, I show how to use the Google Apps Script onOpen(e) Trigger Function on Google Sheets. I show two examples of how the function can be used.

How to Video:

Video Notes:

  • Legacy Apps Script Editor Used in Video
  • Apps Script (Script Editor) is now located under tab ‘Extensions’ instead of ‘Tools’ on Google Sheets

Code in Video:

function onOpen(e) {
  
  // Add a custom menu to the spreadsheet.
  SpreadsheetApp.getUi() // Or DocumentApp, SlidesApp, or FormApp.
      .createMenu('Custom Menu')
      .addItem('First item', 'menuItem1')
      .addToUi();
  
  SpreadsheetApp.getActiveSpreadsheet().getSheetByName('OPEN').getRange(1,2).setValue('NOW');
  
}

function menuItem1() {
  
 SpreadsheetApp.getActiveSpreadsheet().getSheetByName('OPEN').getRange(1,1).setValue('CURT'); 
  
  
}

Related Posts

On Selection Change Google Sheets Copy Row Using onSelectionChange(e) Trigger on Google Sheets - In this post, I demonstrate how to use the onSelectionChange(e) trigger function in an application that copies Rows from one sheet to another.
Google onEdit(e) Function How to use the onEdit(e) Function on Google Sheets - In the Post, I demonstrate how to use the onEdit(e) Function on Google Sheets. This video focuses on the editing of one cell.
doGet(e) Function Google Script How to Use doGet(e) Function to Start HTML Google Web App - In this post, I show three different examples of how to use the doGet(e) function to start the HTML Google Web Application.