Subscribe to events in VBA?

蓝咒 提交于 2019-12-10 22:08:51

问题


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?


回答1:


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 assing a name of a macro to this property (as a string), and it will be called on button press.



来源:https://stackoverflow.com/questions/6216031/subscribe-to-events-in-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!