Antille Seb
May 11th, 1999, 07:13 AM
I build an MFC application that can export data to excel. Everything works
fine with Excel95, but when I try it with Excel 97, I have problems.
I can open Excel 97 and export my data from my application, but when I try
to close Excel from the "File" menu and "Quit", I receive the message :
"OleMainThreadWndName : excel.exe - Application error".
I check that I release all the COM object references, but not much
successfulI. I also try to use SmartPointer and finally COleDispatcher, but
always the same message.
I work with Visual C++ 5.0 SP3, NT4.0 SP3 and Office 97 SP2.
Does anyone had the same problem ?
Thanks in advance.
See my code below :
// Excel 5
#import "C:\Program Files\MSOffice\Excel\xl5en32.olb" rename("Excel",
"Excel5") rename("DialogBox", "DialogBoxXL")
using namespace Excel5 ;
// Excel 8
#import "D:\Program Files\Microsoft Office\Office\mso97.dll" no_namespace
rename("DocumentProperties", "DocumentPropertiesXL")
#import "C:\Program Files\Fichiers communs\Microsoft
Shared\VBA\vbeext1.olb" no_namespace
#import "D:\Program Files\Microsoft Office\Office\excel8.olb"
rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL")
rename("DocumentProperties", "DocumentPropertiesXL") no_dual_interfaces
using namespace Excel ;
_ApplicationPtr pXL;
try {
pXL.CreateInstance(L"Excel.Application.8");
pXL->Visible = VARIANT_TRUE ;
WorkbooksPtr pBooks = pXL->Workbooks;
_WorkbookPtr pBook = pBooks->Add((long)xlWorksheet);
_WorksheetPtr pSheet = pXL->ActiveSheet;
pSheet->Name = "Market Share!";
pSheet->Range["A2"]->Value = "Company A";
pSheet->Range["A3"]->Value = 75.0;
RangePtr pRange = pSheet->Range["A2:D3"];
_ChartPtr pChart = pBook->Charts->Add();
pChart->ChartWizard((Range*) pRange, (long) xl3DPie, 7L, (long) xlRows,
1L, 0L, 2L, "Market Share");
pBook->Saved = VARIANT_TRUE;
pXL->UserControl = VARIANT_TRUE ;
pXL->Release() ;
} catch(_com_error &e) {
}
Antille Sébastien
fine with Excel95, but when I try it with Excel 97, I have problems.
I can open Excel 97 and export my data from my application, but when I try
to close Excel from the "File" menu and "Quit", I receive the message :
"OleMainThreadWndName : excel.exe - Application error".
I check that I release all the COM object references, but not much
successfulI. I also try to use SmartPointer and finally COleDispatcher, but
always the same message.
I work with Visual C++ 5.0 SP3, NT4.0 SP3 and Office 97 SP2.
Does anyone had the same problem ?
Thanks in advance.
See my code below :
// Excel 5
#import "C:\Program Files\MSOffice\Excel\xl5en32.olb" rename("Excel",
"Excel5") rename("DialogBox", "DialogBoxXL")
using namespace Excel5 ;
// Excel 8
#import "D:\Program Files\Microsoft Office\Office\mso97.dll" no_namespace
rename("DocumentProperties", "DocumentPropertiesXL")
#import "C:\Program Files\Fichiers communs\Microsoft
Shared\VBA\vbeext1.olb" no_namespace
#import "D:\Program Files\Microsoft Office\Office\excel8.olb"
rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL")
rename("DocumentProperties", "DocumentPropertiesXL") no_dual_interfaces
using namespace Excel ;
_ApplicationPtr pXL;
try {
pXL.CreateInstance(L"Excel.Application.8");
pXL->Visible = VARIANT_TRUE ;
WorkbooksPtr pBooks = pXL->Workbooks;
_WorkbookPtr pBook = pBooks->Add((long)xlWorksheet);
_WorksheetPtr pSheet = pXL->ActiveSheet;
pSheet->Name = "Market Share!";
pSheet->Range["A2"]->Value = "Company A";
pSheet->Range["A3"]->Value = 75.0;
RangePtr pRange = pSheet->Range["A2:D3"];
_ChartPtr pChart = pBook->Charts->Add();
pChart->ChartWizard((Range*) pRange, (long) xl3DPie, 7L, (long) xlRows,
1L, 0L, 2L, "Market Share");
pBook->Saved = VARIANT_TRUE;
pXL->UserControl = VARIANT_TRUE ;
pXL->Release() ;
} catch(_com_error &e) {
}
Antille Sébastien