I have added a reference Microsoft Excel 5.0 Object Library in my project.
the code is as follows:
Dim myExcel As Excel.Application ' Interface to Excel
Dim myWorkBookCollection As Excel.Workbooks ' Workbook-collection
Dim myWorkBook As Excel.Workbook ' Single Workbook (spreadsheet-collection)
Dim myWorkSheet As Excel.Worksheet ' Single spreadsheet
Dim fdlg As OpenFileDialog = New OpenFileDialog()
fdlg.Title = "VB.NET Corner Open File Dialog"
'fdlg.InitialDirectory = "c:\"
fdlg.Filter = "Excel Files (*.Xls)|*.Xls"
fdlg.FilterIndex = 2
fdlg.RestoreDirectory = True
If fdlg.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
txtFile.Text = fdlg.FileName
End If
myExcel = GetObject(, "Excel.Application")
If myExcel Is Nothing Then
MessageBox.Show("Could not load Excel.exe")
Exit Sub
End If
' initialise access to Excel's workbook collection
myExcel.Visible = True
myWorkBookCollection = myExcel.Workbooks
'open spreadsheet from disk
myWorkBook = myWorkBookCollection.Open(txtFile.Text, , False)
'get 1st sheet from workbook
myWorkSheet = myWorkBook.Sheets.Item(1)
'display the spreadsheet
'myExcel.Visible = True 'Read Cell A2
Dim myCell2 As Object = myWorkSheet.Range("A2", System.Reflection.Missing.Value)
Me.Text = myCell2.Value 'save and get out
myWorkBook.Save()
myExcel.Quit()
now its giving error at this line
" myWorkBook = myWorkBookCollection.Open(txtFile.Text, , False)"
it gives Member Not Found. whereas .open is there in the list.
plz find the solution.