Click here to see your recently viewed pages and most viewed pages.
Hide
Apps Script

Scripts Bound to Google Sheets, Docs, or Forms

A script is bound to a Google Sheets, Docs, or Forms file if it was created from that document rather than as a standalone script. Bound scripts generally behave like standalone scripts except that they do not appear in Google Drive, they cannot be detached from the file they are bound to, and they gain a few special privileges over the parent file.

Note that scripts can also be bound to Google Sites, but these scripts are almost always deployed as web apps. Scripts bound to Sheets, Docs, or Forms can also become web apps, although this is uncommon.

Creating a bound script

To create a bound script, open a Google Sheets, Docs, or Forms file, then select Tools > Script editor. To reopen the script in the future, do the same thing. Because bound scripts do not appear in Google Drive, that menu is the only way to find or open the script.

Special methods

Bound scripts can call a few methods that standalone scripts cannot:

For more information, see the guide to extending Google Sheets or the guide to extending Google Docs.

Custom menus, dialogs, and sidebars

Bound scripts can customize Google Sheets, Docs, and Forms by adding custom menus and dialog boxes or sidebars. Keep in mind, however, that a script can only interact with the user interface for the current instance of an open file. That is, a script bound to one document cannot affect the user interface of another document.

Add-ons

Add-ons run inside Google Sheets, Docs, and Forms. If you've developed a bound or standalone script and want to share it with the world, Apps Script lets you publish your script as an add-on so other users can install it from the add-on store.

Triggers

Bound scripts can use simple triggers like the special onOpen() function, which runs automatically whenever a file is opened by a user who has edit access. Like all types of scripts, they can also use installable triggers.

Custom functions

A custom function is a function in a script bound to Google Sheets that you call directly from a cell using the syntax =myFunctionName(). Custom functions are thus similar to the hundreds of built-in functions in Sheets like AVERAGE or SUM except that you define the custom function's behavior.

Access to bound scripts

Only users who have permission to edit a spreadsheet, document, or form can run its bound script. Collaborators who have only view access cannot open the script editor, although if they make a copy of the parent file, they become the owner of the copy and will be able to see and run a copy of the script.