Excel 2010 Interop - Can load Excel 2003 and 2010 files, but not 2007? RRS feed

  • Question

  • I'm developing an application to load an Excel file using Interop in VB.NET.

    I'm able to load Excel 2003 and Excel 2010 files perfectly with interop, but when i try to load an XLSX file that i presume to be made with Excel 2007, it just doesn't work and give me this error message:

    "Excel cannot open the file '... .xlsx' because the file format or file extension is not valid.  Verify that the file has not been corrupted and that the file extension matches the format of the file".

    If i open Excel 2010 and try to open this file, it work without any problem.  If i keep the file opened in Excel, and run my program, it work because it's already loaded in Excel...

    So there is a problem with the Open method.  I would really appreciate some help here.

    Here's the code:

    Dim oExcel as Microsoft.Office.Interop.Excel.Application
    Dim oWB as Microsoft.Office.Interop.Excel.Workbook

    oExcel = new Microsoft.Office.Interop.Excel.Application
    oWB = oExcel.Workbooks.Open("C:\MyFile.xlsx")

    Thank you

    Wednesday, January 12, 2011 8:04 AM


  • I've found out my problem.  But i want to keep this thread here so if another person encounter the same problem, i want it to be solved in a minute, not in few hours just like i did.

    In my program, i was opening an OleDbConnection to connect to this same file thru this provider: Microsoft.ACE.OLEDB.12.0

    I guess that this connection is opened in read/write, so this mean that the file was ALREADY OPENED/LOCKED.

    A simple "FILE ALREADY IN USE" would be better than "...because the file format or file extension is not valid".

    Thursday, January 13, 2011 3:53 PM