Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 18th, 2007, 09:58 AM
Authorized User
 
Join Date: Jul 2006
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.

 
Old August 18th, 2007, 10:37 PM
Authorized User
 
Join Date: Aug 2007
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)



 
Old August 21st, 2007, 05:52 PM
Authorized User
 
Join Date: Jul 2006
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 ;)

 
Old August 22nd, 2007, 03:42 AM
Authorized User
 
Join Date: Aug 2007
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 ,

 
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
 
Old May 6th, 2009, 08:43 PM
Friend of Wrox
 
Join Date: Sep 2005
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)
 
Old August 31st, 2009, 11:04 PM
Authorized User
 
Join Date: Apr 2008
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





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 11:27 AM
how can read excel file abrahamchempanal RSS and Atom 0 February 22nd, 2006 10: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.