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.

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