开发者

Subscribe to events in VBA?

开发者 https://www.devze.com 2023-03-09 20:37 出处:网络
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 syn

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号