在 VBA 中订阅事件?
我是否正确理解,除了使用 VBA 编辑器的控件名称 + 事件名称组合框之外,您无法订阅事件?没有像 C# 等其他语言那样的combobox.change+=eventhandler 语法,是吗?
Did I understood correctly that you can't subscribe to an event other than using the VBA Editor's control name + event name comboboxes? There is no combobox.change+=eventhandler syntax available as in other languages like C#, is there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正确的。事件处理是通过 VB6/VBA 中的命名约定完成的。
该名称可以是控件 itlsef 的名称,也可以是声明为
WithEvents
的变量。通过为该变量分配不同的引用,您可以开始从该新对象接收事件。这可以看作是动态订阅。然而,某些环境可以提供额外的手段。例如,在 Excel 中,某些可放置对象具有隐藏属性,例如
Button.OnAction
。您可以将宏的名称分配给该属性(作为字符串),按下按钮时将调用该宏。Correct. Event handling is done via naming convention in VB6/VBA.
The name can be the name of the control itlsef, or it can be a variable declared
WithEvents
. By assigning this variable a different reference, you start receiving events from that new object. This can be seen as dynamical subscribing.However, certain environments can provide additional means. For example, in Excel some placeable objects have hidden properties, such as
Button.OnAction
. You can assign a name of a macro to this property (as a string), and it will be called on button press.