VbaObjectsBeginner

Workbook object

Represents an Excel workbook and controls workbook-level automation.

Review the syntaxStudy the examplesOpen the coding app
ThisWorkbook
ActiveWorkbook
Workbooks("Report.xlsx")

This static page keeps the syntax and examples indexed for search, while the coding app handles interactive exploration and saved references.

What it does

Overview

Represents an Excel workbook and controls workbook-level automation.

Workbook references matter whenever a macro opens files, writes reports, or copies sheets between books. Choosing between ThisWorkbook and ActiveWorkbook is a major practical distinction: ThisWorkbook points to the workbook containing the code, while ActiveWorkbook points to whatever workbook currently has focus.

Quick reference

Syntax

ThisWorkbook
ActiveWorkbook
Workbooks("Report.xlsx")

See it in practice

Examples

1

Write to the workbook that owns the macro

ThisWorkbook.Worksheets("Config").Range("B2").Value = Now

ThisWorkbook is usually safer than ActiveWorkbook in automated workflows.

Debug faster

Common Errors

1

LogicError

Cause: Using ActiveWorkbook in a multi-workbook workflow and updating the wrong file.

Fix: Use ThisWorkbook or store the intended workbook in an explicit variable.

Runtime support

Compatibility

Excel desktop VBA

Source: Microsoft Learn Office VBA reference

Common questions

Frequently Asked Questions

Represents an Excel workbook and controls workbook-level automation.

LogicError: Use ThisWorkbook or store the intended workbook in an explicit variable.