Consulting

Results 1 to 6 of 6

Thread: handler for external event

  1. #1

    Exclamation handler for external event

    In Tools/References I added the external application's dll.
    How do I now write an event handler for events generated by that application?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What exactly do you mean? The DLL will handl its events, all you do is call exposed methods.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Quote Originally Posted by xld
    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.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Quote Originally Posted by xld
    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
    Last edited by Bob Phillips; 01-12-2011 at 02:16 AM. Reason: Tidied up the tags

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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

    [vba]

    Private WithEvents mApp As myDLL.MyObject[/vba]

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

    [vba]

    Private Sub mApp_theEvent(sVariable As String)
    '
    End Sub[/vba]

    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.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •