Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Excel iDispatch problem
I have code like this:
IConnectionPoint *pCPSheetEvents, *pCPAppEvents; CExcelEventSink Sink; DWORD dwSheetEventsCookie, dwAppEventsCookie; BOOL bDocSinkInPlace = FALSE, bAppSinkInPlace = FALSE; BOOL __stdcall xlAutoOpen(void) { connect(); CLSID clsid; CLSIDFromProgID(L"Excel.Application", &clsid); IUnknown *pUnk = NULL; bool jest = false; HRESULT hr = GetActiveObject(clsid, NULL, (IUnknown**)&pUnk); if(SUCCEEDED(hr)){ hr = pUnk-QueryInterface(IID_IDispatch, (void **)&pDisp); if(!pDisp) ::MessageBox(NULL, "Failed to find instance!!", "Error", MB_ICONHAND); else{ ::MessageBox(NULL, "Got instance of Excel!", "Success", MB_OK); jest = true; } if (pUnk) pUnk-Release(); } else{ ::MessageBox(NULL, "No active object of Excel!", "Success", MB_ICONHAND); } If user clicks on Excels xls file, Excel is run with active object - this is correct way for my use. But if user starts Excel by executing program file, Excel opens with NO workbook, and my connection is not established. Is there any clue to tell Excel that it should expose to me its EventSink and register my OnWorkbookOpen slot for my function? Or maybe you know how to tell Excel that my function written in C++ as xll should not be volatile but should recalculate all the fields in workbook on workbook open event? Its a function retrieving results from an SQL database, so my boss told me, its useless if the data is saved data, and not fresh grabbed by SQL query. Anybody help? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Colon at the end of excel file name(ex: problem.xls:1, problem.xls | New Users to Excel | |||
Error Message: NULL IDispatch passed to Autowrap() | Excel Discussion (Misc queries) | |||
Exit from Excel edit mode using IDispatch | Excel Discussion (Misc queries) | |||
Started out as an Access problem. Now an Excel problem | Excel Discussion (Misc queries) | |||
different IDispatch in event handler | Excel Programming |