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

发布于 2015-03-25 11:14:40
Control是工作表的代码名,而Plan 1是工作表的选项卡名。后者可以由用户很容易地更改,因此如果可以的话,使用代码名更安全--例如,引用:
control.range("A1:A10")而不是:
sheets("Plan 1").Range("A1:A10")请注意,除非您设置了对该工作簿项目的引用或使用a function that loops through each sheet in the other workbook testing the codename property of each,否则不能使用工作表代码来引用工作簿中包含代码的工作表以外的工作表。
发布于 2015-03-25 11:15:49
"Plan1“是选项卡名,它出现在工作表底部的选项卡上。
"Control“是代码名,可以在VBA中直接引用特定的工作表对象。
Sheets("Plan1").Cells(1, 1).Value和Control.Cells(1, 1).Value将产生相同的输出。
发布于 2016-12-22 22:06:17
VBE中的每个文档类型vbComponent都有一个Name和一个CodeName。
Name是Excel中工作表选项卡上可见的名称。CodeName是工作表对象可以在VBA中引用的名称。示例:
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 Subhttps://stackoverflow.com/questions/29253704
复制相似问题