Getting FileNotFoundException when adding Excel workbook

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.");
}
....
 
J

John Wiese [MS]

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
 
M

Michael Sanford

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top