PDA

View Full Version : handler for external event



Harry Shmed
01-11-2011, 09:17 AM
In Tools/References I added the external application's dll.
How do I now write an event handler for events generated by that application?

Bob Phillips
01-11-2011, 11:12 AM
What exactly do you mean? The DLL will handl its events, all you do is call exposed methods.

Harry Shmed
01-12-2011, 12:53 AM
What exactly do you mean? The DLL will handl its events, all you do is call exposed methods.

Thanks for the reply.
I'm not talking about sending events from excel to the other application but rather the opposite. How to I write the handler to capture events generated by that application. For example it sends an event with a particular object id. I want to inspect that object of that application.

Bob Phillips
01-12-2011, 01:34 AM
I am sorry, I just don't get your question. You interact with the DLL via its API, if it is exposed you can use it.

Harry Shmed
01-12-2011, 01:49 AM
I am sorry, I just don't get your question. You interact with the DLL via its API, if it is exposed you can use it.
I am new to interfacing with a DLL. Although I can write a handler for an excel event (e.g. Workbook_Open) I have no experience with writing the corresponding handler for an event sent from outside excel.

Although I can control that application from excel, I cant do the opposite. For example I can initialize that application object and even change that application's properites:


Set ea = New ExtApp.Application
ea.SomeProperty = True


But when that application generates an event, and it tells me in the documentation that the object Application generates an event called Select, I don't know how to capture that event. Do I need to make an excel class module and put it in there? I've heard that I need to use the Withevents keyword but I don't know the syntax. Perhpas you could give me the sytax for this example.

Thanks

Bob Phillips
01-12-2011, 02:26 AM
This is a bit generic as we are groping in the dark a bit, but as you say, to handle events you create a variable using the WithEvents keyword, and it has to be witin a class module. So, in a new class module, something like



Private WithEvents mApp As myDLL.MyObject

And then the event handler, the signature of which must match the event



Private Sub mApp_theEvent(sVariable As String)
'
End Sub

VBA can generate the event handler signature for you if you select the object in the (General) dropdown at the top of the code window.In the dropdown to the right of that you will then see the events available. Select the event and VBA writes the signature for you.