Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Thisworkbook.name and Activeworkbook.name in VBA

Tags:

excel

vba

Is there any difference between Thisworkbook and ActiveWorkbook.

Example code :

  Sub workbook_name()
     MsgBox Thisworkbook.name
  End Sub



 Sub active_name()
     MsgBox Activeworkbook.name
  End Sub

Both will return the same output,

Is there any other instances where we have to use particularly ThisWorkbook where ActiveWorkbook doesn't work

like image 400
hackwithharsha Avatar asked Feb 16 '16 08:02

hackwithharsha


1 Answers

Activeworkbook.name is used to get the name of the active workbook from n different number of opened workbooks.

Thisworkbook.name is used to get the name of the workbook in which the code is written or stored in the module of that workbook.

E.g if you are writing the code in the module or sheet of workbook A then Thisworkbook.name will return A no matter which is the activeworkbook

like image 97
Stupid_Intern Avatar answered Oct 09 '22 09:10

Stupid_Intern