首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VBE中的工作表名称

VBE中的工作表名称
EN

Stack Overflow用户
提问于 2015-03-25 10:56:40
回答 4查看 314关注 0票数 2

我注意到我的工作簿对于VBE中的每个组件都有两个不同的名称。name1和name2有什么区别?我应该参考哪一个,所以我将确定我的宏将工作?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2015-03-25 11:14:40

Control是工作表的代码名,而Plan 1是工作表的选项卡名。后者可以由用户很容易地更改,因此如果可以的话,使用代码名更安全--例如,引用:

代码语言:javascript
复制
control.range("A1:A10")

而不是:

代码语言:javascript
复制
sheets("Plan 1").Range("A1:A10")

请注意,除非您设置了对该工作簿项目的引用或使用a function that loops through each sheet in the other workbook testing the codename property of each,否则不能使用工作表代码来引用工作簿中包含代码的工作表以外的工作表。

票数 5
EN

Stack Overflow用户

发布于 2015-03-25 11:15:49

"Plan1“是选项卡名,它出现在工作表底部的选项卡上。

"Control“是代码名,可以在VBA中直接引用特定的工作表对象。

Sheets("Plan1").Cells(1, 1).ValueControl.Cells(1, 1).Value将产生相同的输出。

票数 2
EN

Stack Overflow用户

发布于 2016-12-22 22:06:17

VBE中的每个文档类型vbComponent都有一个Name和一个CodeName

  • Name是Excel中工作表选项卡上可见的名称。
  • CodeName是工作表对象可以在VBA中引用的名称。

示例:

代码语言:javascript
复制
Sub Names()

  Debug.Print Control.Name              'Prints "Plan 1"
  Debug.Print Control.CodeName          'Prints "Control"

  'This approach uses the sheet name in a call to `Sheets`,
  ' which will break if a user changes the name of the sheet
  'The sheets collection returns an object, so you don't get
  ' Intellisense, or compile-time error checking
  Debug.Print Sheets("Plan 1").Name     'Prints "Plan 1"
  Debug.Print Sheets("Plan 1").CodeName 'Prints "Control"

End Sub
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29253704

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档