Hi guys I'm having a problem in opening excel files using the workbook.open for me to save all the changes made by oledbcommands.

Dim MyConnection As New OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0; Data Source='" & path & "'; Extended Properties=Excel 12.0;")

        MyConnection.Open()

        Dim i = 0
        Dim h = Label1.Text
        Do
            'Dim q = DataGridView1.Rows(i).Cells(0).Value.ToString
            Dim r = DataGridView1.Rows(i).Cells(2).Value.ToString
            Dim bc = DataGridView1.Rows(i).Cells(1).Value.ToString
            sql = "Update [" & ComboBox1.Text & "$] Set Designation = '" & r & "' Where F2 = '" & bc & "'"
            Dim updt As OleDbCommand = New OleDbCommand(sql, MyConnection)
            updt.ExecuteNonQuery()
            i = i + 1

        Loop While (i < h)

        MyConnection.Close()

        xlWorkBook = xlApp.Workbooks.Open(path)

        xlWorkBook.Save()

        xlWorkBook.Close()

I just recycled it from my other project. The error it shows is this: Excel cannot open the file 'Incentive Template.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. I even test my previous project(which is also an excel file) and it's still working. I even tried to make a new one and still no luck. Is there any solution to this? I'm stuck.

Hi,
Do you have Excel installed on the machine? and if so, is it a version later than 2003? i.e. 2007 onwards to handle xlsx files? Or could something have changed the file associations?

Also you are opening the file by interop when you get the error not as a datasource. How are you referencing the Excel Application? By adding a reference to the Excel interop to the project? OR do you use late binding?

If you are using a reference, is it the correct one? i.e. pointing to a 2007 onwards version (v12) and not 2000, 2003 etc.. (you said it was based on an old project and both assemblies could be on the same machine, esp if you have installed a newer version over the older one...) If you you late binding then it should just use whichever version of excel is installed:

sub LateBindToExcel(byRef mypath as string)
'Example of Late binding - will use whichever version of excel is installed
dim xlapp as object = CreateObject("Excel.Application")
dim xlWorkbook as object = xlapp.WorkBooks.Open(path)
end sub

Problem solved! Looks like I forgot to close my OleDb Connection. It felt like missing a semi-colon hahaha. Thanks for replying anyway. Oh and yes I do have Excel installed 2007

This question has already been answered. Start a new discussion instead.