Difference between Thisworkbook.name and Activeworkbook.name in VBA

后端 未结 1 1562
忘掉有多难
忘掉有多难 2020-12-02 00:04

Is there any difference between Thisworkbook and ActiveWorkbook.

Example code :

  Sub workbook_name()
     MsgBox Thisworkbook.name
  End Sub



 Sub         


        
相关标签:
1条回答
  • 2020-12-02 00:47

    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

    0 讨论(0)
提交回复
热议问题