VBA Difference Between ActiveWorkbook ThisWorkbook In Excel

VBA Difference Between ActiveWorkbook ThisWorkbook In Excel. ThisWorkbook represents the current workbook in which the code is available. ActiveWorkbook represents the currently active workbook from multiple different open Workbooks.

VBA Difference Between ActiveWorkbook and ThisWorkbook

Let us see the VBA Difference Between ActiveWorkbook and ThisWorkbook.

ActiveWorkbook ThisWorkbook
ActiveWorkbook represents the Workbook in active window which has focus on the screen. ThisWorkbook represents the current Workbook in which the current VBA code is running or executing.
The Workbook window is active / visible. The Workbook window is Inactive / Invisible.
Get Active Workbook Name:
Get Current Workbook Name:
Activate ActiveWorkbook:
ActiveWorkbook .Activate
Activate ThisWorkbook:
ThisWorkbook .Activate

'VBA Get Active Workbook Name
Sub VBA_Get_ActiveWorkbook_Name()
    'Variable declaration
    Dim sActiveWorkbookName As String
    sActiveWorkbookName = ActiveWorkbook.Name
End Sub

'VBA Get Current Workbook Name
Sub VBA_Get_CurrentWorkbook_Name()
    'Variable declaration
    Dim sCurrentWorkbookName As String
    sCurrentWorkbookName = ThisWorkbook.Name
End Sub

Related Workbook Object articles

You may also like the related Workbook Object articles.

VBA Workbook Object

Leave a Comment

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