How to Activate a Specific Workbooks in Excel Using VBA
Activate Workbook or Worksheet
If you know the name of the workbook You can use the following code to Activate Workbook or worksheet. For example workbook name is “Book2” which we want to activate and it contains sheet named as “Sheet1”. Using following code you can Activate Workbook Or Work Sheet.
Sub Activate_Workbook() 'Activate Workbook Workbooks("Book2.xls").Activate 'Activate Worksheet Workbooks("Book2.xls").Sheets("Sheet1").Activate End Sub
VBA Activate Worksheet –
Please see the below VBA codes to activate Worksheet. In this example we are activating a Worksheet named “Project1”.
Sub Activate_Sheet() Worksheets("Project1").Activate 'Or Sheets("Project1").Activate End Sub
VBA Activate Worksheet Method– with Number: Example 2
Please see the below VBA code or macro procedure to activate Worksheet. In this example we are activating first Worksheet in the active workbook.
Sub Activate_Sheet_BasedOnIndex() Worksheets(1).Activate 'Or Sheets(1).Activate End Sub