| Start |
|---|
Sources and Handlers What are events?VBA is event-driven: VBA code runs in response to events raised by the host application or the host document - understanding events is fundamental to understanding VBA. APIs often expose objects that raise a number of events in response to various states. For example an From an API perspective, events are extension points: the client code can chose to implement code that handles these events, and execute custom code whenever these events are fired: that's how you can execute your custom code automatically every time the selection changes on any worksheet - by handling the event that gets fired when the selection changes on any worksheet. An object that exposes events is an event source. A method that handles an event is a handler. HandlersVBA document modules (e.g. The right-side dropdown lists the members of the interface selected in the left-side dropdown: The VBE automatically generates an event handler stub when an item is selected on the right-side list, or navigates there if the handler exists. You can define a module-scoped Each Only types that expose at least one event can be used with The object reference must be SourcesAny class module (or document module, or user form) can be an event source. Use the The signature of the event determines how the event is raised, and what the event handlers will look like. Events can only be raised within the class they're defined in - client code can only handle them. Events are raised with the Without code that handles the |
Passing data back to the event source Using parameters passed by referenceAn event may define a If the Assuming the Using mutable objectsYou could also pass a copy of a mutable object Combined with the The handler would look like this: SyntaxRemarks |
Read Article
https://develop.horje.com/learn/1434/reference