VBA Activate Workbook

Written by

Editorial Team

Reviewed by

Steve Rynearson

Last updated on July 19, 2021

This tutorial will demonstrate how to activate a workbook using VBA.

Activate Workbook

Activate with Object Name

The most obvious way to activate a workbook is by referencing its name in the Workbooks Object.

Workbooks("book1.xlsm").Activate

Activate with Workbook Number

However, you can also activate workbooks by referring to their “number”. The workbook number is determined by the order in which the workbooks were opened.

So workbook 1 is the first opened workbook, workbook 2 is the second, etc.

Workbooks(2).Activate

Activate ThisWorkbook

The ThisWorkbook Object is the workbook where the running code is stored. To activate ThisWorkbook use this line of code:

ThisWorkbook.Activate

ActiveWorkbook

Once a workbook has been activated, it becomes the ActiveWorkbook. To see the ActiveWorkbook you can use this line of code to fetch the ActiveWorkbook name:

Msgbox ActiveWorkbook.Name

 

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as


Learn More!
vba-free-addin

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)

Free Download

Return to VBA Code Examples