473,797 Members | 3,204 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

38 New Member
I have added a reference Microsoft Excel 5.0 Object Library in my project.
the code is as follows:
Dim myExcel As Excel.Applicati on ' Interface to Excel
Dim myWorkBookColle ction 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.InitialDi rectory = "c:\"
fdlg.Filter = "Excel Files (*.Xls)|*.Xls"
fdlg.FilterInde x = 2
fdlg.RestoreDir ectory = True
If fdlg.ShowDialog () = System.Windows. Forms.DialogRes ult.OK Then
txtFile.Text = fdlg.FileName
End If

myExcel = GetObject(, "Excel.Applicat ion")
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
myWorkBookColle ction = myExcel.Workboo ks
'open spreadsheet from disk

myWorkBook = myWorkBookColle ction.Open(txtF ile.Text, , False)
'get 1st sheet from workbook
myWorkSheet = myWorkBook.Shee ts.Item(1)
'display the spreadsheet
'myExcel.Visibl e = True 'Read Cell A2
Dim myCell2 As Object = myWorkSheet.Ran ge("A2", System.Reflecti on.Missing.Valu e)
Me.Text = myCell2.Value 'save and get out
myWorkBook.Save ()
myExcel.Quit()

now its giving error at this line
" myWorkBook = myWorkBookColle ction.Open(txtF ile.Text, , False)"

it gives Member Not Found. whereas .open is there in the list.
plz find the solution.
Jan 22 '08 #1
0 939

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

Similar topics

4
6661
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 HTTP-EQUIV="content-type" CONTENT="text/html; charset=utf-8"> ' create and open the connection to the Excel file Set conn = Server.CreateObject("ADODB.Connection") conn.Open "DRIVER=Microsoft Excel Driver (*.xls);" & "DBQ=" &...
1
4631
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 from this Excel file and store them in a struct/class for further processing. (mostly just display the info in graphical format) This is not some sort of database application, but rather I am
1
3663
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 by a form. The class can instantiate Excel, open a new workbook, add a new worksheet, get a range, and put some data in it. So, I have basically just duplicated what KB 302902 does, except I am working out of a managed C++ class. The problem...
12
6025
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 examples, I found its printing of cell's contents in a different manner. print sh.row(rx)
2
3097
by: wstsoi | last post by:
hi I have to read images from spreadsheet, is it possible to do with php?
0
10469
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10209
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10023
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9066
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7560
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6803
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2934
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.