Extend Google Docs, Sheets, and Forms with Apps Script

While macros are currently not supported in Google Drive, you can extend the capabilities of Google Docs, Sheets, and Forms by adding custom menus, dialogs, and sidebars with Google Apps Script, a simple yet powerful scripting language based on JavaScript. In Google Sheets, Apps Script also lets you write custom spreadsheet functions.

If you're familiar with Visual Basic for Applications in Excel, then you'll likely catch on to Apps Script quickly. Apps Script also allows you to build web applications and interact with many other Google services, including AdSense, Analytics, Calendar, Drive, Finance, Gmail, and Maps.

Apps Script for beginners

If you’d like to learn Apps Script but you’re new to programming, Codecademy offers a great online JavaScript course for beginners. (Note that this course was not developed by and is not associated with Google.) Once you feel like you have a handle on JavaScript, try either of these Apps Script quickstart tutorials: Macros, menus, and custom functions or Managing form responses.

You can also check out our gallery of Add-ons, script-based tools built by third-party developers, available in Google Docs and the new Google Sheets.

Apps Script for experienced programmers

Experienced developers should start with a quick introduction to Apps Script’s development environment. After that, the list of tutorials should give you a good idea of what’s possible, or you can jump straight into the reference documentation. We can’t wait to see what you build.

Custom menu items

Custom menus let you add new functionality to the familiar menu system. When the user clicks on a menu option, Apps Script runs a series of instructions (a macro) determined by the script’s author.

For example, a custom menu could include a command that produces a simple report from the data in a spreadsheet and then sends it in an email. This allows users to run scripts without opening the Script Editor or typing a formula.

To learn more about custom menu items and dialog boxes in Sheets, try this tutorial: Defining Spreadsheet Menus. To learn more about custom menu items, dialog boxes, and sidebars in Docs, see the guide to Extending Docs with Apps Script. You can customize the Google Forms editor using exactly the same techniques as Docs, but note that these customizations are only visible to the person who is creating the form, not in the view that form respondents see.

Apps Script in Sheets

Custom functions

A custom function (sometimes called a user-defined function) is similar to a spreadsheet formula like ‘=SUM(A1:A5)’ except that you define the formula’s behavior in Apps Script. For example, you could create a custom function, in2mm(), that converts a value from inches to millimeters, then use the formula in your spreadsheet by typing ‘=in2mm(A1)’ or ‘=in2mm(10)’ into a cell.

To learn more about custom functions, get started with this tutorial: Custom Functions in Spreadsheets.

Apps Script gallery

You don’t need to write a single line of code to use Apps Script with Google Sheets — instead, you can try using scripts that have been created by fellow users. In the old version of Google Sheets, you will find these in the Script Gallery. In the new version of Google Sheets, check out Add-ons, our new collection of popular scripts.

You’ll find that many popular scripts are already in the Add-ons gallery in the new version of Sheets. But, If you’re looking for a script you used in the old version of Sheets and can’t find it in the Add-ons gallery, try the following:

  1. Open a spreadsheet created in the old version of Sheets.
  2. Go to the Tools menu > Script manager.
  3. Copy the script you want to use in the new Sheets:
    1. Go to the Tools menu > Script gallery and click Install next to the script.
    2. Accept any permissions and close the script gallery.
    3. Go to the Tools menu > Script editor and copy the script code found there.
  4. Open a spreadsheet created in the new version of Sheets.
  5. Go to the Tools menu > Script editor.
  6. Click Spreadsheet and paste the script into the editor.