A month ago, I asked about the automation of MS word.
(
Automation of already-running MS word[
^])
and thanks to the members of codeproject, I solved my problem.
But at this time, it is Excel.
I tried the same thing with Excel and got an error message 'rejected by callee' (code
= 0x80010001).
When I trying to handle existing excel application, COM returns that error.
So I did googling and have read almost all articles about 'rejected by callee' and tried to fix that error.. it fails..
Please help me again with this..
Below is my simple code.
HWND hwnd = ::GetForegroundWindow();
if (hwnd == NULL)
return;
USES_CONVERSION;
CLSID clsid;
HRESULT hr = CLSIDFromProgID(A2OLE(_T("Excel.Application")), &clsid);
if (hr != S_OK) {
return;
}
IUnknown* pUnk;
hr = GetActiveObject(clsid, NULL, &pUnk);
if (hr == S_OK) {
try {
LPDISPATCH pDispatch = NULL;
hr = pUnk->QueryInterface(IID_IDispatch, (void**)&pDispatch);
ASSERT(!FAILED(hr));
CApplication _iAppInterface;
_iAppInterface.AttachDispatch(pDispatch);
CRange _iRange = _iAppInterface.get_ActiveCell();
}
catch (COleDispatchException* pe) {
pe->ReportError();
pe->Delete();
}
catch (COleException* pe) {
pe->ReportError();
pe->Delete();
}
pUnk->Release();
}
What I have tried:
At the time above code runs in background, Excel is activated and I type a letter.
And my office365 Excel is fully licensed by the company I work for.
Thanks.