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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Interop.Excel open file problem

Status
Not open for further replies.

npongar

Programmer
Oct 3, 2003
12
0
0
CA
Hi everyone,

I'm having a problem automating Excel XP using the Office XP Primary Interop Assemblies.

In my code I successfully instantiate an Excel Application class, and I can add a new workbook no problem. The trouble comes when I'm trying to open an existing workbook. Whenever I try to open a workbook I get the following error:

'blah.xls' could not be found. Check the spelling of the file name, and verify that the file location is correct.

If you are trying to open the file from your list of most recently used files on the File menu, make sure that the file has not been renamed, moved, or deleted.

The file does exist though. What's really weird is that when I create a new workbook using excelApp.Workbooks.Add() and save it, I can open that workbook later using excelApp.Workbooks.Open() and I won't get the error. I've looked through the existing files (that cause the error) and the ones I created from my c# code (no error) for differences that could cause this but I've gotten no-where.

Anyone have any ideas/sage-like advice?
 
This works for me, using the Excel 9.0 object:


Code:
// create Excel Automation Object
Excel.Application xlObj = new Excel.Application();

// open the spreadsheet
Excel.Workbook wb = xlObj.Workbooks.Open(FILENAME,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing);

Be sure that the string FILENAME is correct.

Thomas D. Greer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top