Board index » delphi » Callback function in Excel VBA

Callback function in Excel VBA

How do I define a callback functin in Excel VBA so that a DLL that excel
uses can call this callback function in Excel VBA.  The advantage is the
user can define his call back function and pass it to DLL.

Please help.  Thanks in advance.

 

Re:Callback function in Excel VBA


Hi Dennis,

This is perhaps not the right newsgroup to post your question. But I'll
answer it anyway.

You must create a Class Module in VBA. Then you let the Class Module
instanciate your COM object and receive the events as they come.

An example of the Class Module code:

        Option Explicit
        Private WithEvents MyCOMObject As MyCOMClass

        Sub Class_Initialize()
            Set MyCOMObject = New MyCOMClass
        End Sub

        Sub Class_Terminate()
            Set MyCOMObject = Nothing
        End Sub

        Sub MyCOMObject_OnMyEvent
            ' Here comes the code for the event
        End Sub

In any case, the WithEvents is your keyword here. Read about it in the
VBA help.

Beware of one thing. Excel 97 does guarantee to deliver the event to
it's destination. If Excel is busy, it simply drops the event in some
cases.

Hope this helps.

Henrik

Quote
Dennis Poon wrote:

> How do I define a callback functin in Excel VBA so that a DLL that excel
> uses can call this callback function in Excel VBA.  The advantage is the
> user can define his call back function and pass it to DLL.

> Please help.  Thanks in advance.

Other Threads