VBA Activate Workbook in Excel

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.

VBA Activate Workbook

Syntax for Activate Workbook Method

Here is the following syntax to activate Workbook in Excel VBA using activate 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.

'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
    'Activate second Workbook
End Sub

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

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
    'Activate Third Workbook
End Sub

Instructions to use Macro

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.

Related Workbook Object articles

You may also like the related Workbook Object articles.

VBA Workbook Object

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 Comment

Your email address will not be published. Required fields are marked *