NekoManu Posted July 11, 2008 Posted July 11, 2008 I have never tried this before, so I have been looking for a workng example. So far no luck. I want to open an Excel 2007 file in VB.Net. When I try I get an error: Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD)) I have no idea what is going on. This is the code I'm using: Private Sub btnExcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExcel.Click Dim xlApp As Excel.Application Dim xlWorkBook As Excel.Workbook Dim xlWorkSheet As Excel.Worksheet xlApp = New Excel.ApplicationClass xlWorkBook = xlApp.Workbooks.Open("C:\Test.xlsx") xlWorkSheet = xlWorkBook.Worksheets("sheet1") 'display the cells value B2 MsgBox(xlWorkSheet.Cells(2, 2).value) 'edit the cell with new value xlWorkSheet.Cells(2, 2) = "http://vb.net-informations.com" xlWorkBook.Close() xlApp.Quit() releaseObject(xlApp) releaseObject(xlWorkBook) releaseObject(xlWorkSheet) End Sub Private Sub releaseObject(ByVal obj As Object) Try System.Runtime.InteropServices.Marshal.ReleaseComObject(obj) obj = Nothing Catch ex As Exception obj = Nothing Finally GC.Collect() End Try End Sub Quote
techmanbd Posted July 12, 2008 Posted July 12, 2008 It could be you are using an excel library in VB that is not compatible with the Excel program on the computer. I had the same problem a few years back, read this thread and it may help you. Using Late Binding is what you may need. http://www.xtremedotnettalk.com/showthread.php?t=79754&highlight=excel Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
Recommended Posts