Subscribe to events in VBA?
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.
精彩评论