473,386 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

To read an excel file with Excel Class in vb.net

38
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.
Jan 22 '08 #1
0 1404

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: see_mun_lee | last post by:
I use asp to develop a web page to read an excel file containing Chinese Character then display it in the web page. Unfortunately, I cant display it!!! it will display (?????????). <META...
1
by: Esmail Bonakarian | last post by:
Greetings all, What is the best way to access specific records in an Excel file? I have an Excel file, I want to randomly and repeatedly (maybe around up to 50 times) draw some rows of data...
1
by: J Daniel Melton | last post by:
Hello, I am using late binding in a managed VC++ .NET 2003 application. I used KB 302902 (for C#) as a starting point and converted it to managed C++. I built a managed class that is intantiated...
12
by: kath | last post by:
How do I read an Excel file in Python? I have found a package to read excel file, which can be used on any platform. http://www.lexicon.net/sjmachin/xlrd.htm I installed and working on the...
2
by: wstsoi | last post by:
hi I have to read images from spreadsheet, is it possible to do with php?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.