Return to VBA Code Examples

VBA Activate Workbook

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.

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.

Activate ThisWorkbook

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

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:

 

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!