Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Automation Open Existing XL File eOleException (DESPERATE)

Status
Not open for further replies.

6volt

Programmer
Jun 4, 2003
74
US
This post is an act of DESPERATION.

This is code I have written and used for years and now, out of the blue, I cannot open an existing XL file.

The code is the traditional:
Code:
Excel: = CreateOleObject (' excel.application ');
...
Excel. Workbooks. Open (LongFileName1); 
...
Excel. Workbooks. Open (LongFileName2);

LongFileName1 opens just fine.
LongFileName2 produces the eOleException.

LongFileName2 has a Type of .C01 which is an output from a neural network program and is in Excel 4.0 format.

I have done the following to try and find this error:

1) Check existence of file in the code preceeding the above.
2) Opened LongFileName by navigating to its directory in Explorer, double clicking on it, and successfully having Excel open it. (I have Type .C01 setup to be opened by Excel. This has worked for many years for me.)
3) reduced the length of the full path LongFileName which is around 200 characters long. I deal with long paths/filenames all the time in this code and I am confident I am shorter than ones that work OK.

The fact that the file does exist and can be opened by doubled clicking but yet, cannot be opened by this old code is mind-boggling.

I am open to all suggestions no matter how obvious or cryptic.

The only debugging method I know of now is "verbose:" Create a test program with the code above where the files are nice short path/names. Show that works, and then step by step begin modifying the working code to the exact code I have now that doesn't work. At some point, I'll do a step that produces the error.

I really hate to have to spend the time to eek this out - unfortunately I'm in melt down mode and haven't seen daylight in days.

Thanks in advance,
Regards,
Tom
 
Problem Solved and it was stupid.

Turns out the XL file was corrupt.

I opened it up at least twice until I put some showmessages in the code to stop right before I opened it so I could try opening it through explorer and I guess I finally clicked on the right file.

In my defense, the file names consist of a date, day, seed, training "time code" if you will so it would not be that difficult to pick the wrong file.

I guess I was loopy enough, late in the evening to do just that.

Anyhow, everything works as it should.
________________________________________________

However, I did learn a little thing. When I encapsulated the open in a TRY EXCEPT, I lost the MS EOleException message which had the information "Cannot open file."

So I wonder how I could use the Try Except AND get the MS error msg?

Tom
 
You can still get to the error message:

Code:
except
   on E : Exception do
   begin
      ShowMessage('Exception class name = '+E.ClassName);
      ShowMessage('Exception message = '+E.Message);
   end;
end;
 
Thanks!

At least some good thing resulted from this!

Regards,
Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top