Error when create Excel 2007 file in Visual Basic 2008
I wanna create an empty Excel 2007 file thru Visual Basic 2008. I added reference to "Microsoft Excel 12.0 Object Library" from "COM" tab of "Add reference" window.
I wrote following code, but it fails to run - VS 2008 points on "xlBook = xlApp.Workbooks.Add()" line and says - "Old format is used or library has wrong type. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))"
What is the reason?
Code (on usual button):
Option Strict Off
Imports MyExcel = Microsoft.Office.Interop.Excel
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xlApp As New MyExcel.Application()
Dim xlBook As MyExcel.Workbook
Dim xlSheet As MyExcel.Sheets()
xlBook = xlApp.Workbooks.Add()
xlSheet = xlBook.Worksheets("Sheet1")
xlApp.Visible = True
End Sub
|