Hi,
I want to open Excel 2007 file then retrieve some data inside. I used this code, let's say under Form1_Load:
Code:
Imports Microsoft.Office.Interop
...
Dim xlApp As New Excel.Application, xlWorkbook As Excel.Workbook
Dim xlWorksheet As Excel.Worksheet
Try
' The following line always fails
xlWorkbook = xlApp.Workbooks.Open(My.Application.Info.DirectoryPath & _
"\Work Report.xlsx")
xlWorksheet = xlWorkbook.Sheets("April 2008")
Label1.Text = xlWorksheet.Cells("B2")
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
...
I have added a reference to Microsoft Excel 12.0 Object Library.
When I test this code, I always get an error:
System.Runtime.InteropServices.COMException (0x80028018):
Old format or invalid type library.
(Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))
à à à at Microsoft.Office.Interop.Excel.Workbooks.Open(Stri ng Filename,
Object UpdateLinks, Object ReadOnly, Object Format, Object Password,
Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin,
Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru,
Object Local, Object CorruptLoad)
à à à at Sample.Form3.Form3_Load(Object sender, EventArgs e) in
D:\My Documents\Visual Studio 2008\Projects\Sample\Sample\Form3.
vb:line 24
The
VB 2008 samples about Excel application also don't work and throw the same exception.
I already did a workaround as written here:
http://blogs.msdn.com/eric_carter/ar...15/429515.aspx
(since my locale is set to Indonesian), but it also didn't work.
Does anyone know how to overcome this in
VB 2008 Express Edition?
Thank you.