VBA Activate Workbook

VBA Activate Workbook in Excel

VBA Activate Workbook in Excel method VBA helps to deal with multiple workbooks. It helps to activate specified Workbook window first. Sometimes we may need to activate specific workbook. We can activate specific workbook with Workbook Name or Index number.

Syntax for Activate Workbook Method

Here is the following syntax to activate Workbook in Excel VBA using activate method.

Workbooks.Activate

Where activate is a method.

Macro to Activate Workbook with Workbook Name in Excel VBA

Let us see the following example. It activate Workbook with Workbook Name in Excel VBA. In the below example ‘sWorkbook1’ and ‘sWorkbook2’ represent workbook names. First we are trying to activate workbook ‘sWorkbook1’ and then activating workbook ‘sWorkbook2’ file. Activate method helps to activate workbook.

'Activate Workbook with Workbook Name in Excel VBA
Sub VBA_Activate_Workbook_with_Workbook_Name()

    'Variable declaration
    Dim sWorkbook1 As String
    Dim sWorkbook2 As String
    
    'you can change two Workbook file paths here
    sWorkbook1 = "D:\VBAF1\WB1.xlsm"
    sWorkbook2 = "D:\VBAF1\WB2.xlsm"
    
    'Activate first Workbook
    Workbooks(sWorkbook1).Activate
    
    'Activate second Workbook
    Workbooks(sWorkbook2).Activate
        
End Sub

VBA Code to Activate Workbook with Workbook Index Number in Excel VBA

Here is the following example. Before running below macro procedure three workbooks should be open. Then only we can notice how the workbooks are active based on index number. VBA Code to Activate Workbook with Workbook Index Number in Excel VBA. In the below example Workbooks(1) represents the first workbook. Similarly Workbooks(3) indicates the third workbook. where numbers 1 and 3 are index numbers of workbook.

'Activate Workbook by Index Number in Excel VBA
Sub VBA_Activate_Workbook_by_Index_Number()
    
    'Activate first Workbook
    Workbooks(1).Activate
    
    'Activate Third Workbook
    Workbooks(3).Activate
     
End Sub

Instructions to Run VBA Macro Code or Procedure:

You can refer the following link for the step by step instructions to execute VBA procedure or code.

Instructions to run VBA Macro Code

Other Useful Resources:

Click on the following links of the useful resources. These helps to learn and gain more knowledge.

VBA Tutorial VBA Functions List VBA Arrays in Excel Blog

VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers

2 thoughts on “VBA Activate Workbook in Excel”

  1. This is really interesting, You are a very skilled blogger.
    I have joined your rss feed and look forward to seeking more of your magnificent
    post. Also, I’ve shared your site in my social networks!

Leave a Reply