Getting FileNotFoundException when adding Excel workbook

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Sanford

    #1

    Getting FileNotFoundException when adding Excel workbook

    I'm getting a Sysmte.IO.FileN otFoundExceptio n 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.Applicati on app = new Excel.Applicati on();
    if (app == null) {
    Console.WriteLi ne("ERROR: EXCEL couldn't be started!");
    return false;
    }

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

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

    Console.WriteLi ne ("Adding a new workbook");

    try {
    _Workbook workbook = workbooks.Add(X lWBATemplate.xl WBATWorksheet);

    } catch (System.IO.File NotFoundExcepti on) {
    Console.WriteLi ne("Always gets here.");
    }
    ....
  • John Wiese [MS]

    #2
    Re: Getting FileNotFoundExc eption when adding Excel workbook

    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
    --
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at
    http://www.microsoft.com/info/cpyright.htm



    "Michael Sanford" <msanford1030@c omcast.net> wrote in message
    news:d3b0fcf9.0 307280301.c5a28 8@posting.googl e.com...[color=blue]
    > I'm getting a Sysmte.IO.FileN otFoundExceptio n 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.Applicati on app = new Excel.Applicati on();
    > if (app == null) {
    > Console.WriteLi ne("ERROR: EXCEL couldn't be started!");
    > return false;
    > }
    >
    > Console.WriteLi ne ("Making application visible");
    > app.Visible = true;
    >
    > Console.WriteLi ne ("Getting the workbooks collection");
    > Workbooks workbooks = app.Workbooks;
    >
    > Console.WriteLi ne ("Adding a new workbook");
    >
    > try {
    > _Workbook workbook = workbooks.Add(X lWBATemplate.xl WBATWorksheet);
    >
    > } catch (System.IO.File NotFoundExcepti on) {
    > Console.WriteLi ne("Always gets here.");
    > }
    > ...[/color]


    Comment

    • Michael Sanford

      #3
      Re: Getting FileNotFoundExc eption when adding Excel workbook

      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


      "John Wiese [MS]" <jwiese@online. microsoft.com> wrote in message news:<eEjkLhQVD HA.2052@TK2MSFT NGP10.phx.gbl>. ..[color=blue]
      > 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
      > --
      > This posting is provided "AS IS" with no warranties, and confers no rights.
      > Use of included script samples are subject to the terms specified at
      > http://www.microsoft.com/info/cpyright.htm
      >
      >
      >
      > "Michael Sanford" <msanford1030@c omcast.net> wrote in message
      > news:d3b0fcf9.0 307280301.c5a28 8@posting.googl e.com...[color=green]
      > > I'm getting a Sysmte.IO.FileN otFoundExceptio n 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.Applicati on app = new Excel.Applicati on();
      > > if (app == null) {
      > > Console.WriteLi ne("ERROR: EXCEL couldn't be started!");
      > > return false;
      > > }
      > >
      > > Console.WriteLi ne ("Making application visible");
      > > app.Visible = true;
      > >
      > > Console.WriteLi ne ("Getting the workbooks collection");
      > > Workbooks workbooks = app.Workbooks;
      > >
      > > Console.WriteLi ne ("Adding a new workbook");
      > >
      > > try {
      > > _Workbook workbook = workbooks.Add(X lWBATemplate.xl WBATWorksheet);
      > >
      > > } catch (System.IO.File NotFoundExcepti on) {[/color]
      > Console.WriteLi ne("Always gets here.");[color=green]
      > > }
      > > ...[/color][/color]

      Comment

      Working...