简体   繁体   English

VBA中Thisworkbook.name和Activeworkbook.name之间的区别

[英]Difference between Thisworkbook.name and Activeworkbook.name in VBA

Is there any difference between Thisworkbook and ActiveWorkbook. Thisworkbook和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 是否有任何其他情况我们必须使用ActiveWorkbook不起作用的ThisWorkbook

Activeworkbook.name is used to get the name of the active workbook from n different number of opened workbooks. Activeworkbook.name用于从n个不同数量的已打开工作簿中获取活动工作簿的名称。

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. Thisworkbook.name用于获取在该工作簿的模块中编写或存储代码的工作簿的名称。

Eg 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 例如,如果您正在编写工作簿A的模块或工作表中的代码,那么Thisworkbook.name将返回A无论哪个是活动工作簿

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 相当于starbasic的Workbooks(ThisWorkbook.Name) - Workbooks(ThisWorkbook.Name) equivalent in starbasic Excel VBA-如果activeworkbook是thisworkbook - Excel VBA - if activeworkbook is thisworkbook ActiveWorkbook.Name 是否返回字符串? 新问题:说“文件已损坏” - Does ActiveWorkbook.Name return a string? New issue: says "file corrupted" 在 Format (Date) 元素之前返回 (ThisWorkbook.name) 元素的正确方法 - Proper way to return elements of (ThisWorkbook.name) before the element of Format (Date) Windows(ThisWorkbook.Name).Visible = True 导致 Excel 的自动恢复文件出错 - Windows(ThisWorkbook.Name).Visible = True causes error on Excel's auto-recovered files Excel.ThisWorkbook和ThisWorkbook之间的区别? - Difference between Excel.ThisWorkbook and just ThisWorkbook? 一旦我们更改为活动工作簿,就不会在活动工作簿上执行Excel 2016 VBA活动工作簿操作 - Excel 2016 VBA activeworkbook actions are not done on activeworkbook once we change to thisworkbook VBA 中的 Name 和 FullName 有什么区别? - What is the difference between Name and FullName in VBA? 按名称访问工作表,包括 ThisWorkbook - Access Worksheet by name including ThisWorkbook 如何将连接名称视为ActiveWorkbook.Excel VBA中的连接的参数 - How can treat the connection name as parameter in ActiveWorkbook.Connections in Excel VBA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM