Workbook object
Represents an Excel workbook and controls workbook-level automation.
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
Write to the workbook that owns the macro
ThisWorkbook.Worksheets("Config").Range("B2").Value = NowThisWorkbook is usually safer than ActiveWorkbook in automated workflows.
Debug faster
Common Errors
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
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.