Use the Activate method with the workbook’s file name, including the extension:
Workbooks("Sales.xlsx").Activate
A file that has never been saved has no extension yet, so use its name alone: Workbooks("Book3").Activate. Leaving the extension off a saved file works on some PCs and fails on others, depending on whether Windows is set to hide file extensions, so always include it.
Use ThisWorkbook.Activate to return to the file that holds the macro. Workbooks(2).Activate activates by position, but the number follows the order the files were opened and counts hidden files such as PERSONAL.XLSB, so it rarely points where you expect.
The workbook has to be open, or you get “Subscript out of range” (error 9). Open it with Workbooks.Open "C:\Reports\Sales.xlsx", which also activates it, or test whether it is open before activating:
Dim wb As Workbook
On Error Resume Next
Set wb = Workbooks("Sales.xlsx")
On Error GoTo 0
If wb Is Nothing Then
MsgBox "Sales.xlsx is not open"
Else
wb.Activate
End If
Most code does not need to activate a workbook at all. Refer to it directly, as in Workbooks("Sales.xlsx").Worksheets("Data").Range("A1").Value = 100. This runs faster and keeps working when a different file ends up active.
When you are working with multiple workbooks at the same time, I mean, when you have more than one workbook open at the same time, then you need to know the method that can help you activate a workbook that you want to work on.

To activate a workbook using VBA, you need to use the Workbook.Activate method. In this method, you need to specify the workbook name using the Workbooks collection. It also allows you to use the workbook number instead of the workbook name, but you can only refer to the open workbooks.
In this tutorial, we look at different ways to use this method.
Steps to Activate a Workbook

- Type “Workbooks” to use the Workbooks collection.
- Specify the workbook name in the double quotation marks.
- Enter a dot (.) to get the list of properties and methods.
- Select the Activate method from the list, or you can also type it.
- In the end, run the code to activate the workbook.
Sub vba_activate_workbook() Workbooks("Book3").Activate End Sub
Note: If you try to activate a workbook that is not open, VBA will show an error (Run-time error 9: Subscript out of range).

Related: Activate a Worksheet using VBA
Activate a Workbook by using the Number
When you have multiple workbooks open, all those workbooks are part of the Workbooks collection and have a number (in the order they were opened) that you can use to refer to them, and then you can use the Activate method with it. Here’s the code:
Sub vba_activate_workbook() Workbooks(2).Activate End Sub

And if you are trying to activate a workbook using a number that doesn’t exist, VBA will show you Run-time error ‘9’ (Subscript out of Range).
Be careful with numbers: hidden workbooks, like your Personal Macro Workbook (PERSONAL.XLSB), are also in the collection, so Workbooks(1) may not be the workbook you see first. Names are safer than numbers.

Activate ThisWorkbook
You can refer to the workbook where you are writing code by using the ThisWorkbook property. Let’s say you have five workbooks open at the same time, but the code is in “Book1.xlsm”, so when you run the following code, it will activate “Book1.xlsm”.
Sub vba_activate_workbook() ThisWorkbook.Activate End Sub
Check Before Activating a Workbook
As I said, when you try to activate a workbook that is not open, VBA will show you an error. To deal with this problem, the best way is to check for the workbook name first (whether it’s open or not) and then activate it.
Sub vba_activate_workbook() Dim wb As Workbook For Each wb In Workbooks If wb.Name = "Book3.xlsx" Then wb.Activate MsgBox "Workbook found and activated" Exit Sub End If Next wb MsgBox "Not found" End Sub
By using the above code, you can specify a workbook name, and it will first check for that workbook in all the open workbooks, and if it finds the workbook, it will activate it.
Notes
- When you are using the name of the workbook, make sure to use the correct file extension.
- If you want to activate a workbook that is not yet saved, then you need to use only the name of that workbook without suffixing the file extension.
Activate a Workbook by a Part of Its Name
Sometimes the file name changes, like a report with a date in its name. In that case, look for a part of the name with InStr. The following code activates the first open workbook whose name has “Sales” in it:
Sub activate_by_partial_name()
Dim wb As Workbook
For Each wb In Workbooks
If InStr(1, wb.Name, "Sales", vbTextCompare) > 0 Then
wb.Activate
Exit Sub
End If
Next wb
MsgBox "No workbook with Sales in its name is open."
End Sub
Activate a Workbook and a Sheet in It
To go to a specific sheet in another workbook, activate the workbook first and then the sheet:
Sub activate_workbook_and_sheet()
Workbooks("Book3.xlsx").Activate
Worksheets("Sheet2").Activate
End Sub
Keep in mind that you don’t need to activate a workbook to work with it. You can read and change its data directly, like Workbooks(“Book3.xlsx”).Worksheets(“Sheet2”).Range(“A1”).Value = 10, which is faster and doesn’t change what you see on the screen.
Frequently Asked Questions
Why do I get “Subscript out of range” when activating a workbook?
The workbook isn’t open, or the name in the code doesn’t match. For a saved file, include the extension, like “Book3.xlsx”, and check the spelling and spaces.
What is the difference between ActiveWorkbook and ThisWorkbook?
ActiveWorkbook is the workbook you see on the screen right now. ThisWorkbook is the workbook that has the code, wherever it is.
Can I activate a workbook that is closed?
No. Open it first with Workbooks.Open and its full path. Workbooks.Open also makes the workbook active, so you don’t need Activate after it.
Written by
Puneet Gogia
Microsoft MVP — Excel · Founder, Excel Champs
Twelve years of teaching Excel, and a decade before that using it as a data analyst. Every tutorial here is written from a file I actually built.