Activate Another Workbook with VBA in Excel: 6 Examples

Method 1 – Activate Another Workbook by Workbook Name in Excel VBA

This example will help you activate another workbook by closing your existing workbook when you apply this VBA Macro and put your filename.

Activate Another Workbook by Workbook Name in Excel VBA

  • Copy the following code and paste it into the above Module. Click on Run to see the output.
Sub Activate_AnotherWorkbook_Using_FileName()
    'Activating the workbook by its name
    Workbooks("Activate Another Workbook.xlsm").Activate
End Sub

Save your Excel file and Run the code. You will see the following:

Go through the whole process and see the output video link in the above section where we have included one, as all the output videos are the same.


Method 2 – Using Object Variable to Activate Another Workbook in Excel VBA

Get a clear concept of activating a workbook by using a simple macro with an object variable.

Using Object Variable to Activate Another Workbook in Excel VBA

  • Copy the following code and paste it into the above Module. Click Run to see the output.
Sub Activate_AnotherWorkbook_With_ObjectVariable()
    'Declaring variable
    Dim ObjectVar As Workbook
    'Assigning the workbook filename to variable
    Set ObjectVar = Workbooks("Activate Another Workbook.xlsm")
    'Activating the workbook
    ObjectVar.Activate
End Sub

Go through the whole process and see the output video link in the above section where we have included one, as all the output videos are the same.


Method 3 – Activate Another Workbook by Number in Excel VBA

Use a specific workbook number to activate this particular workbook with the help of a simple macro.

Activate Another Workbook by Number in Excel VBA

  • Copy the following code and paste it into the above Module. Click Run to see the output.
Sub Activate_AnotherWorkbook_ByNumber()
    'Using Workbook number to activate
    Workbooks(1).Activate
End Sub

Go through the whole process and see the output video link in the above section where we have included one, as all the output videos are the same.


Method 4 – Activate Another Workbook with a Specific Worksheet in Excel VBA

We will demonstrate an example where we will activate a workbook with a specific sheet by using a very convenient way.

Activate Another Workbook with a Specific Worksheet in Excel VBA

  • Copy the following code and paste it into the above Module. Click on Run to see the output.
Sub Activate_AnotherWorkbookAndWorksheet()
    'Activating the particular workbook with particular worksheet
    Workbooks("Activate Another Workbook.xlsm").Worksheets("Employee_Information").Activate
End Sub

Go through the whole process and see the output video link in the above section where we have included one, as all the output videos are the same.


Method 5 – Using InStr Function to Activate Another Workbook with Partial Filename in Excel VBA

See that we will activate another workbook by closing the existing workbook with the help of a Macro, where we will apply the VBA InStr function and put the partial filename in the code.

Using Instr Function to Activate Another Workbook with Partial Filename in Excel VBA

  • Copy the following code and paste it into the above Module. Click Run to see the output.
Sub Activate_AnotherWorkbook_With_PartialFilename_Using_InStrFunction()
    'Declaring variable
    Dim Myworkbook As Workbook
    'Applying For Each loop to loop through all the workbooks
    For Each Myworkbook In Application.Workbooks
        'Using If statement to activate our desired workbook by looping through all the workbooks
        If InStr(1, Myworkbook.Name, "Activate Another", vbBinaryCompare) > 0 Then Myworkbook.Activate
    Next Myworkbook
End Sub

Go through the whole process and see the output video link in the above section where we have included one, as all the output videos are the same.


Method 6 – Using Like Operator to Activate Another Workbook in Excel VBA

Apply the Like operator in the VBA code to activate another workbook in Excel.

Using Like Operator to Activate Another Workbook in Excel VBA

  • Copy the following code and paste it into the above Module. Click Run to see the output.
Sub Activate_AnotherWorkbook_Using_LikeOperator()
    'Declaring variable
    Dim Myworkbook As Workbook
    'Using For Each loop to loop through all the workbooks
    For Each Myworkbook In Application.Workbooks
        'Using If condition with Like operator to activate the particular workbook
        If Myworkbook.Name Like "Activate Another Workbook*.xlsm" Then Myworkbook.Activate
    Next Myworkbook    
End Sub

Go through the whole process and see the output video link in the above section where we have included one, as all the output videos are the same.


Frequently Asked Questions

1. If I don’t see another workbook mentioned in the “Switch Windows” menu, how can I activate it?

The workbook you wish to activate might be minimized or hidden behind another window if it isn’t listed in the “Switch Windows” menu. You can either use the keyboard shortcut “Alt + F6” to cycle among the open Excel windows or try clicking on the Excel icon in the taskbar.

2. Is there a faster way in Excel to transition between open workbooks?

To swiftly switch between open worksheets in Excel, press “Ctrl + Tab” on your keyboard. Each workbook will be cycled through in the order they were opened. The “Ctrl + Shift + Tab” keyboard shortcut can also be used to cycle through workbooks in reverse.

3. Can I activate multiple workbooks simultaneously?

By selecting each workbook you want to activate in the “Switch Windows” option while holding down the “Ctrl” key, you can activate multiple workbooks at once. You can work with all of the selected workbooks at once because they will all be engaged.


Download Practice Workbook

You may download the following Excel workbook for better understanding and practice it yourself.

Get FREE Advanced Excel Exercises with Solutions!
Bishawajit Chakraborty
Bishawajit Chakraborty

Bishawajit Chakraborty, a Rajshahi University of Engineering & Technology graduate with a B.Sc. in Mechanical Engineering, has been associated with ExcelDemy since 2022. Presently, he is a content developer, specializing in Excel Power Query, Data Analysis and VBA. It is worth mentioning that he has authored more than 90 articles on VBA content development. His profound interest lies in the fields of data analytics and data science. He possesses expertise in VBA, Power BI, machine learning, and Python... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo