[MFC] How to catch Excel events RRS feed

  • Question




    I use MFC to do Excel automation and i would like to know how to catch Excel events like sheet_calculate() or sheet_change() ... It is possible to do this in VBA, so I think it is also possible with MFC but i don t know how!

    I looked into my Excel object library (12) and i got CAppEvents and CWorkbookEvents classes but i dont know how to use them.

    Thank for you help


    Monday, May 19, 2008 3:03 PM


  • As mentioned in the Newsgroup posting.


    Open the class that contains the Excel control.  In the property window select events. Expand the item with the id of the control.  Find the event you want to catch, to its right, click the drop down button, and select add.


    You should get something like this for SheetCalculate

    Code Snippet

    BEGIN_EVENTSINK_MAP(CExcelTestDlg, CDialog)

    ON_EVENT(CExcelTestDlg, IDC_SPREADSHEET1, 1516, SheetCalculateSpreadsheet1, VTS_DISPATCH)


    void CExcelTestDlg::SheetCalculateSpreadsheet1(LPDISPATCH Sh)
    // TODO: Add your message handler code here


    Monday, May 19, 2008 4:24 PM