Getting FileNotFoundException when adding Excel workbook

  • Thread starter Thread starter Michael Sanford
  • Start date Start date
M

Michael Sanford

I'm getting a Sysmte.IO.FileNotFoundException when executing the code
below.
It is straight from the example. This works on one machine, but not
the other. Other benign calls invoke the same misbehavior which as
ActiveWorkbook or Active Worksheet.

Please help!

peace,
- mike

Excel.Application app = new Excel.Application();
if (app == null) {
Console.WriteLine("ERROR: EXCEL couldn't be started!");
return false;
}

Console.WriteLine ("Making application visible");
app.Visible = true;

Console.WriteLine ("Getting the workbooks collection");
Workbooks workbooks = app.Workbooks;

Console.WriteLine ("Adding a new workbook");

try {
_Workbook workbook = workbooks.Add(XlWBATemplate.xlWBATWorksheet);

} catch (System.IO.FileNotFoundException) {
Console.WriteLine("Always gets here.");
}
....
 
Michael,

Which line of the code do you get the error on? What is the difference
between machines that it works on and ones it doesn't? Is the version of
Excel the same on all the machines?

John Wiese
 
I found the problem. Excel had trouble loading some libraries at
startup (nothing to do with my C# application). I reinstalled Office
and everything "now works".

peace,
- mike
 
Back
Top