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.
Table of Contents:
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: ActiveWorkbook.Name |
Get Current Workbook Name: ThisWorkbook.Name |
Activate ActiveWorkbook: ActiveWorkbook .Activate |
Activate ThisWorkbook: ThisWorkbook .Activate |
Example:
'VBA Get Active Workbook Name Sub VBA_Get_ActiveWorkbook_Name() 'Variable declaration Dim sActiveWorkbookName As String sActiveWorkbookName = ActiveWorkbook.Name End Sub |
Example:
'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.