VBA Activate Workbook: Methods, Examples, and Fixes

VBA & macros · Updated November 18, 2026

To activate an open workbook in Excel VBA, retrieve it from the Workbooks collection by its exact name and call its Activate method; if it is not open, open it first and then activate it. Activation makes that workbook current in Excel, but it does not necessarily select a particular worksheet or cell.

What activating a workbook does

Excel keeps track of an active workbook: the workbook that receives actions directed at the current window. In VBA, activating a workbook changes which open workbook is active in the Excel application instance running the macro. This matters when a procedure refers to objects indirectly, such as the active sheet or the active cell. Those references can point somewhere different after a workbook is activated.

Activation is not the same as opening a file. A workbook must already be open before you can activate it through the Workbooks collection. Nor is activation the same as selecting a worksheet, cell, or range. A workbook remembers its active sheet, so activating it normally brings that workbook and its current sheet into focus; it does not choose a new sheet for you.

Use activation when the macro needs to make a workbook current for the user or for later code that deliberately relies on the active workbook. If your goal is simply to read or change data, it is often safer to refer directly to a workbook, worksheet, and range without changing the active window.

Activate a workbook that is already open

The simplest approach is to identify the workbook by its Name, including its file extension, and activate the resulting Workbook object. For example, if the open file is named Sales Report.xlsx, the following procedure targets that workbook. Before running any macro, save a copy of the workbook: VBA changes cannot be undone with Ctrl+Z.

Sub ActivateOpenWorkbook()
    ' Activate a workbook that is already open.
    Dim wb As Workbook

    Set wb = Workbooks("Sales Report.xlsx")
    wb.Activate
End Sub

Run the procedure while the workbook is open in the same Excel instance as the macro. The name in the collection must match the workbook’s displayed file name, including the extension. If the file is named Sales Report.xlsm, for instance, using the .xlsx name will not find it. A missing or misspelled name usually raises a run-time error rather than silently choosing another workbook.

You can put a macro in a standard module in the workbook that contains it, in another open macro-enabled workbook, or in the Personal Macro Workbook. The code’s location does not change which workbook the Workbooks reference targets; the string passed to the collection still identifies the workbook to activate.

Choose a reliable way to identify the target

Using the workbook name is convenient when the user has already opened the file and there is no ambiguity about which open workbook is intended. A full file path is more informative when a macro needs to find a particular file, especially if different folders could contain similarly named files. The Workbooks collection is local to one Excel application instance, so a macro does not search every Excel process running on the computer.

To compare full paths, check each open workbook’s FullName property. This example looks for a matching path without regard to letter case, then activates the match. Change the sample path to the actual location. Save a copy before running the macro, because any subsequent VBA edits cannot be reversed with Ctrl+Z.

Sub ActivateWorkbookByPath()
    ' Find an already open workbook by its full path.
    Dim targetPath As String
    Dim candidate As Workbook
    Dim wb As Workbook

    targetPath = "C:\Reports\Sales Report.xlsx"
    For Each candidate In Application.Workbooks
        If StrComp(candidate.FullName, targetPath, vbTextCompare) = 0 Then
            Set wb = candidate
            Exit For
        End If
    Next candidate

    If Not wb Is Nothing Then wb.Activate
End Sub

This version only activates a workbook that is already open; it does not open a file when no match is found. The FullName check also makes the intended folder explicit. Use a path format valid for the computer running Excel, and confirm that the file is actually available there. If you choose to add file-opening behavior, handle the possibility that the path is wrong, a network location is unavailable, or Excel cannot access the file.

Open a workbook and then activate it

If the file may not be open, use Workbooks.Open and keep the Workbook object it returns. The returned object gives the macro a direct reference to the file, rather than requiring it to look the file up again by name. Opening a workbook often makes it active as a side effect, but an explicit Activate call documents the intention and ensures the target is current at that point in the procedure.

Save a backup copy before running the macro. Opening a file can display prompts or cause linked-data and read-only behavior depending on the file and Excel settings; do not assume that opening a workbook has made it safe to edit.

Sub OpenAndActivateWorkbook()
    ' Open the specified file, then make it active.
    Dim filePath As String
    Dim wb As Workbook

    filePath = "C:\Reports\Sales Report.xlsx"
    Set wb = Workbooks.Open(Filename:=filePath)
    wb.Activate
End Sub

If the file is already open, opening it again is unnecessary and may lead to a duplicate-open warning or other behavior depending on the situation. A more complete routine can first search Application.Workbooks by FullName, then call Workbooks.Open only if no matching workbook is found. For shared or important files, add appropriate error handling and decide in advance what the macro should do if the file is missing or opens read-only.

ThisWorkbook and ActiveWorkbook are different

A common source of bugs is treating ThisWorkbook and ActiveWorkbook as interchangeable. ThisWorkbook means the workbook that contains the running VBA code. ActiveWorkbook means the workbook that is currently active in Excel. They may be the same, but they are often different when code is stored in the Personal Macro Workbook, an add-in, or a separate controller workbook.

For example, a macro stored in a controller file can activate a report workbook. After that call, ActiveWorkbook will normally refer to the report, while ThisWorkbook still refers to the controller. Use ThisWorkbook when the procedure must work with the file that holds its code. Use an explicitly assigned Workbook variable when it must work with a particular target. Avoid relying on ActiveWorkbook in a long procedure if another action could change which workbook is active.

The same principle applies to worksheets. ActiveSheet refers to the active sheet, while a worksheet variable refers to the specific sheet assigned to it. Explicit references are easier to review and less likely to send a change to the wrong file.

Activate a worksheet after activating its workbook

If the real task is to show a particular sheet, identify both the workbook and the worksheet. After you have a Workbook object, activate the workbook and then its worksheet. Worksheets contains worksheet tabs; it does not include chart sheets. If a tab might be a chart sheet, the broader Sheets collection can address it, but code should use the collection that matches the intended sheet type.

Sub ActivateSummarySheet()
    ' Activate a workbook and one of its worksheets.
    Dim wb As Workbook
    Dim ws As Worksheet

    Set wb = Workbooks("Sales Report.xlsx")
    Set ws = wb.Worksheets("Summary")
    wb.Activate
    ws.Activate
End Sub

Here, both names must exist in the open workbook. If the workbook is open but has no worksheet named Summary, the worksheet lookup raises an error. A worksheet’s Activate method also brings its parent workbook into focus, so activating the workbook first is not always necessary when you already have the worksheet reference. The separate calls can nevertheless make the intended sequence clear.

For data processing, activation is usually optional. VBA can read or write a known range through a worksheet object without selecting the sheet or changing what the user sees. That approach also avoids code that depends on Selection or ActiveCell, which can change unexpectedly.

Common activation errors and how to fix them

  • Workbook not found: Check spelling, spaces, and the extension. Confirm that the file is open in the same Excel instance. A short name passed to Workbooks is not a substitute for a complete path when you need to distinguish files by location.
  • Workbook is not open: Workbooks refers to open workbooks, not every file on disk. Use Workbooks.Open with a valid path if the macro is meant to open the file, and account for access or file errors.
  • Wrong workbook is active: Replace implicit references such as ActiveWorkbook with the Workbook variable you assigned to the intended file. Check whether the code is running from an add-in or Personal Macro Workbook.
  • Worksheet lookup fails: Verify the tab’s exact name and whether it is a worksheet or chart sheet. A workbook can activate successfully even though a later lookup for a missing sheet fails.
  • The visible result seems unchanged: The workbook may already be active, or its previously active sheet may be the one currently displayed. Activation does not select a new cell. If you need a particular sheet, activate it explicitly; if you need a particular cell, reference or select it separately.
  • Macro does not run: Excel for the web can open VBA-containing files but does not run VBA macros. Use desktop Excel and ensure the file and macro are permitted by the organization’s security settings.

When diagnosing a problem, check the exact line that fails and inspect the workbook’s Name and FullName properties in the VBA editor. Distinguish an error in the workbook lookup from an error later in the procedure. This helps avoid masking a missing-file problem with broad error suppression.

Windows, Mac, and Excel for the web

The Workbook Activate method and the basic object model are available in desktop Excel for Microsoft 365 on Windows and Mac. On Windows, open the Visual Basic Editor with Alt+F11; you can also use Developer > Visual Basic on the ribbon. On Mac, Option+F11 opens the editor on many keyboards; a keyboard that assigns function keys to hardware controls may also require Fn. The Mac ribbon can expose the Developer tab through Excel > Settings (or Preferences, depending on the build) > Ribbon & Toolbar.

File paths are a practical platform difference: a Windows path such as the example above will not identify a file stored at a Mac location. Use the correct path for the computer running the macro, and do not assume a workbook is available at the same location on both systems. Excel for the web does not execute VBA, so a macro that activates a workbook must be run in desktop Excel.

Frequently Asked Questions

How do I activate a workbook by name in VBA?
Use the Workbooks collection to get the open workbook by its exact file name, including the extension, assign it to a Workbook variable, and call Activate. The workbook must be open in the same Excel instance.

Does Workbooks.Open automatically activate a workbook?
Opening a workbook commonly makes it active, but code should keep the returned Workbook object and call Activate when an explicit activation is part of the intended workflow. That makes the target clear and avoids depending on an implicit state change.

What is the difference between ThisWorkbook and ActiveWorkbook?
ThisWorkbook is the file containing the running code. ActiveWorkbook is the file currently active in Excel. They can differ when the code runs from an add-in, Personal Macro Workbook, or another controller workbook.

Can I activate a workbook without selecting a worksheet?
Yes. Activating the workbook does not require selecting a new worksheet or cell. Excel displays the workbook’s active sheet; use a worksheet reference and its Activate method only when you need a specific sheet to become current.

Can VBA activate a workbook in Excel for the web?
No. Excel for the web does not run VBA macros. Open the file in desktop Excel for Windows or Mac to run VBA that activates a workbook.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.