Activate Workbook method in Excel 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.
Here is the following syntax to activate Workbook in Excel VBA using activate method.
Let us see the following example. It activate Workbook with Workbook Name in Excel VBA.
'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 sWorkbook1 = "D:\VBAF1\WB1.xlsm" sWorkbook2 = "D:\VBAF1\WB2.xlsm" 'Activate first Workbook Workbooks(sWorkbook1).Activate 'Activate second Workbook Workbooks(sWorkbook2).Activate End Sub
Here is the following example. VBA Code to Activate Workbook with Workbook Index Number in Excel VBA.
'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
Here are the instructions to use above macro procedure in Visual basic editor.
- Open Visual Basic Editor(VBE) by clicking Alt +F11
- Go to code window by clicking F7
- Copy above specified macro or procedure
- Paste above copied code in code window
- Run macro by clicking F5 or Run command
- You can see output on the screen
- Find above output screenshot of the specified procedure.
You may also like the related Workbook Object articles.