What replaces ThisWorkbook in Google Sheets?

In Excel VBA, ThisWorkbook refers to the file that hosts the code. In Apps Script bound to a spreadsheet, call SpreadsheetApp.getActiveSpreadsheet() for the same idea. Standalone scripts use openById or openByUrl with the spreadsheet ID from the URL.

When to use it

Use getActiveSpreadsheet when porting ThisWorkbook events or properties to a bound script.

When to skip it

Skip workbook object code when a single formula or IMPORTRANGE already reads the other file.

Better Sheets resources

Related Tutorials

Watch how ThisWorkbook works

Browse more tutorials
MAKE Your Google Sheets Add-on WORK

MAKE Your Google Sheets Add-on WORK

In this section of the Add-on course we'll be making the apps script wor...
The First Thing I Do When Starting a Google Sheet

The First Thing I Do When Starting a Google Sheet

Are you tired of the default look of your Google Sheets? In this video, ...
5 Ways To Use Google Sheets for Advanced Project Management

5 Ways To Use Google Sheets for Advanced Project Management

Here are 5 advanced ways to manage projects inside of Google Sheets Man...
Convert Google Sheets into a REST API

Convert Google Sheets into a REST API

How to use Google Sheets as a database by turning it into a REST API wit...
Get Every Editor on Every Google File I Own

Get Every Editor on Every Google File I Own

Get every editor if you're looking for the sheets and documents you've s...
Scrape Google Maps

Scrape Google Maps

Scrape any query in Google Maps into your Google Sheets. Enter your API ...

Related blog posts

Guides that explain ThisWorkbook in more depth.

Browse the blog

Related terms

Done reading about ThisWorkbook?

Membership unlocks 637+ 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.