Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 18th, 2007, 09:58 AM
Authorized User
 
Join Date: Jul 2006
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to read data from an excel file

Hi guys, i would like to know how to read certain cells from an excel file in order to make a database from them, but first i have to know how to do this.
thanks in advance.

Reply With Quote
  #2 (permalink)  
Old August 18th, 2007, 10:37 PM
Authorized User
 
Join Date: Aug 2007
Location: MANAMA, MANAMA, Bahrain.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to zrtv
Default

Dear ,
To open excel from vb u can use the following code

Dim xcell As String
Dim xl As Object 'To open Excel
Set xl = CreateObject("Excel.application") 'Creates an object
xcell = App.Path & "\test.xls"
xl.Application.Workbooks.Open xcell, , True
xl.Visible = True ' So you can see Excel

'this how a cell reference should be given with this you can write and read from specified cell
xl.Application.Worksheets("sheet1").Cells(6, 8).Value = "TEST"
'in the above line cells(6-is column,8-is rows)



Reply With Quote
  #3 (permalink)  
Old August 21st, 2007, 05:52 PM
Authorized User
 
Join Date: Jul 2006
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

First of all thanks a lot zrtv,

now i have this doubt, how do i close the excel file i just opened, cause i want to read a lot of them in the same dir.

where do you get to know this stuff, is there a book or a website?

thanks a lot in advance ;)

Reply With Quote
  #4 (permalink)  
Old August 22nd, 2007, 03:42 AM
Authorized User
 
Join Date: Aug 2007
Location: MANAMA, MANAMA, Bahrain.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to zrtv
Default

For the vb to excel help better you go to excel itself then go to
vb editor, from the vb editor you can search for the help ,

Reply With Quote
  #5 (permalink)  
Old May 6th, 2009, 07:33 PM
Registered User
 
Join Date: May 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default read excel from visual basic, without re-opening excel

Hello,
My visual basic 6 program has 2 buttons:

1) opens Excel and opens an existing workbook

2) This second button should only read the cells of the already-open workbook. But the button's _Click() subroutine rejected my attempt to pass the open workbook object as an argument.

How do I read workbook cells in an already-open workbook, from a subroutine that did not open the workbook?

Thanks
Reply With Quote
  #6 (permalink)  
Old May 6th, 2009, 08:43 PM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

For example, you want to read the contents A1 of Sheet1 of a workbook named MyWordbook.xls

sValue = xl.Workbooks("MyWordbook.xls").Sheets(1).Range("A1 ").Value

or

sValue = xl.Workbooks("MyWordbook.xls").Sheets(1).Cells(1,1 ).Value


All you need to understand is Excel Application has a "collection" of Workbooks and each workbook has a "collection" of Worksheets/Sheets

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
Reply With Quote
  #7 (permalink)  
Old August 31st, 2009, 11:04 PM
Authorized User
Points: 198, Level: 3
Points: 198, Level: 3 Points: 198, Level: 3 Points: 198, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2008
Location: singapore, singapore, Singapore.
Posts: 54
Thanks: 0
Thanked 4 Times in 4 Posts
Default

hi
for basic understanding of using excel in vb. You may refer this link
VB code to Export Text to Excel and Save. You can use this for understanding how excel can be used in the vb to open,read, save, and close
__________________
Pon Saravanan
VbKnowledgebase.com
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to read data from sybase to excel thillaiarasu SQL Language 2 April 20th, 2007 01:34 AM
Read Data from Excel File kiwibey ASP.NET 2.0 Professional 1 December 5th, 2006 10:27 AM
how can read excel file abrahamchempanal RSS and Atom 0 February 22nd, 2006 09:52 AM
Read Excel File rekha_jsr Classic ASP Basics 2 June 16th, 2005 04:58 AM
Read an uploaded Excel File rekha_jsr Classic ASP Basics 0 June 12th, 2005 10:17 PM



All times are GMT -4. The time now is 09:28 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.