views:

833

answers:

2

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.

A: 

OLE 800A03EC usually has to do with invalid characters in your Excel file. Are you using the same data as your client? Is there a difference in Regional Settings? Etc. etc. there could be number of errors for this, but most likely (as a quick google told me) it is a regional setting.

Roald van Doorn
The regional settings are probably different. The file we use is the same. I need the program to run smoothly on any reginal settings though, so what should I do?
Tofig Hasanov
+2  A: 

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):

  • Your client has Excel open and is editing a cell (select a cell and press F2)
  • Your code starts:
    • You create a TExcelApplication and accesses the Workbooks property. Since your Excel application is not yet connected it calls TOleServer.Connect (look at the implementation of GetDefaultInterface)
    • Since the default connectkind is ckRunningOrNew, TExcelApplication connects to the running instance.
    • Because the client is editing a cell you get an error on the Open method.

How you can prevent this: Set ConnectKind of your TExcelApplication to ckNewInstance so you'll always work in a separate Excel instance.

The_Fox
Thanks, will try this
Tofig Hasanov