I am trying to open excel 2003 workbook and save it as something else, for example excel 95. I use the following code:
XLSApp:=TExcelApplication.Create(Self);
XLSApp.Workbooks.Open(SomeFileName,NULL,false,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,defaultlcid);
XLSWB:=TExcelWorkbook.Create(XLSApp);
XLSWB.ConnectTo(XLSApp.Workbooks.Item[1]);
XLSWB.SaveCopyAs(ExtractFilePath(edTable.Text)+'temp.xls');
XLSWB.SaveAs(SomeOtherFileName,xlExcel7,EmptyParam,EmptyParam,False,False,xlNoChange,xlUserResolution,False,EmptyParam,EmptyParam,EmptyParam,DefaultLCID);
Unfortunately this code gives "Ole 800A03EC" on clients computer, while it works on mine. Note that I have Office 2007 installed, and he has Office 2003 SP3.
Any help would be very much appreciated.
I have seen this error once when automating Excel. It happened when the user had a cell in editmode and you tried to automate that instance. Excel doesn't like it when you are editing a cell and some program is fiddling around in the background.
So this is what's happening at your client (I think):
How you can prevent this: Set ConnectKind of your TExcelApplication to ckNewInstance so you'll always work in a separate Excel instance.
800A03EC also occurs when one (like, me) does a dumb thing like trying to load into an Excel cell that doesn't exist, like:
excel.Cells[rowIndex, ri] = x;
where ri is 0.
NOTE BENE: The col
index starts at 1, not 0.
In my case ( xlExcel8 format ):
Instead of:
theWorkbookWyjscie.SaveAs(saveFileDialog1.FileName, myExcel.XlFileFormat.xlExcel8);
I used:
theWorkbookWyjscie.SaveAs(saveFileDialog1.FileName);
or
theWorkbookWyjscie.SaveAs(saveFileDialog1.FileName, myExcel.XlFileFormat.xlExcel7);
Both work well... And yes, I know this is a stupid solution, but it's working!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With