if (! Execute(m_pWorkbooks,L"Add",&result))
{
CString strError;
strError.Format(_T("Cannot add new work book"));
AfxMessageBox(strError);
return FALSE;
}
if (SUCCEEDED(hr))
{
return TRUE;
}
else
{
// free exception structure information
SysFreeString(excep.bstrSource);
SysFreeString(excep.bstrDescription);
SysFreeString(excep.bstrHelpFile);
return FALSE;
}
}
else
{
return FALSE;
}
}
BOOL CExcel::StartExcel(BOOL bShow)
{
EndExcel();
CLSID clsExcel;
/* Obtain the CLSID that identifies EXCEL.APPLICATION
* This value is universally unique to Excel versions 5 and up, and
* is used by OLE to identify which server to start. We are obtaining
* the CLSID from the ProgID.
*/
HRESULT hr;
if (FAILED((hr=CLSIDFromProgID(L"Excel.Application", &clsExcel))))
{
AfxMessageBox(_T("Cannot start Excel."));
return FALSE;
}
// start a new copy of Excel, grab the IDispatch interface
if (FAILED((hr=CoCreateInstance(clsExcel, NULL, CLSCTX_LOCAL_SERVER,
IID_IDispatch, reinterpret_cast<void**>(&m_pExcel)))))
{
AfxMessageBox(_T("Cannot start Excel."));
return FALSE;
}