如何获取对生成事件的工作表的引用?
在工作表中,我可以将代码附加到事件,如下所示:
Private Sub Worksheet_Calculate()
' .. code here
End Sub
如何获取对生成事件的工作表的引用?
我想要 100% 安全的方式,所以我不这样做必须担心工作表名称更改等情况下的代码破坏。
ActiveSheet
不正确,因为不能保证任何工作表在(重新)计算时处于活动状态。
In a worksheet I can attach code to an event like so:
Private Sub Worksheet_Calculate()
' .. code here
End Sub
How can I get a reference to the worksheet the event was generated in?
I want to have a 100% secure way, so I don't have to worry about code breaking when the name worksheet changes etc.
ActiveSheet
is not correct because it is not guaranteed that any sheet is active upon (re)calculate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用呼叫者:
You can use caller:
您可以使用 Codename 属性:
默认情况下,它与工作表的名称相同,但您可以在 VBE 的属性窗口中更改它 - 它是 Name 属性。用户无法更改它。 (复制工作表会在名称中添加一个数字,例如,Sheet1 变为 Sheet11。
您还可以在工作簿级别的事件中使用它:
很难提供更多帮助,因为您没有说明将如何使用该引用。
You can use the Codename property:
By default it's the same name as the worksheet, but you can change it in the Properties Window of the VBE - it's the Name property. The user can't change it. (Copying a sheet adds a number to the name, e.g., Sheet1 becomes Sheet11.
You can also use it in the workbook-level event:
It's hard to be more helpful as you don't say how you'll use the reference.
有关代码名称的更多信息:
http://www.ozgrid.com/ VBA/excel-vba-sheet-names.htm
Some more information on code names:
http://www.ozgrid.com/VBA/excel-vba-sheet-names.htm