Wrox Programmer Forums
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics 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 16th, 2004, 10:27 AM
Registered User
 
Join Date: Aug 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to belzicool
Default data reading from excel using VB

I am working on a application which needs to read data from a excel file and then, depending on the value, write it to a access file (.mdb)
the problem is that how do i give the condition (till end of file )for the excel sheet
these are the excel and access connections i am using:

Set xlApp = New Excel.Application
xlApp.Workbooks.Open ("E:\nikhil\excel2access\input.xls") 'the excel file is now opened
xlApp.Worksheets("Sheet1").Activate ' the excel worksheet is now active for reading
i = 1
c = 2
Set cn = New Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "E:\nikhil\excel2access\output.mdb;Persist Security Info=False"

cn.Open

cmd.ActiveConnection = cn
 
Old August 16th, 2004, 11:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

You can use the VisibleRows property, but that goes all the way to the end of the sheet. I believe I just checked for the presense of values (where cell still has text). I haven't found a way using the API's where you can stop at the end of the data.

Another approach would be to load the excel sheet as a data source (using the DataAdapter) and access it that way.

Brian
 
Old November 25th, 2005, 06:12 AM
Registered User
 
Join Date: Jun 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
first you need to select first cell and then goto last cell
as given below

objExcel.application.Range("A1").Select
objExcel.application.Selection.End(xlDown).Select

so now you are in the last row

objExcel.application.Selection.End(xlToRight).Sele ct

it takes you to last column

then you can find out which row and which column you are in


Tip: If you want to know anything which is possible in EXCEL using VB
Just Record a macro with all the requirements.then study the macro code....thats it...:D

with thanks
Aditya
 
Old December 22nd, 2005, 06:28 AM
PM PM is offline
Registered User
 
Join Date: Dec 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi All
Hey Aditya..thats a cool idea.. Here is another way for solving it

'VB.NET code
'To select the used range in WorkSheet
        Dim xlWsheet As Excel.Worksheet = xlApp.Worksheets("Sheet1")
        Dim r As Excel.Range = xlWsheet.UsedRange

' To get the first Value
        MsgBox(r.Cells(1, 1).Value)

' TO get the last value
        MsgBox(r.cells(r.rows.count()-1,r.columns.count()-1).value)


Thanks
PM






Similar Threads
Thread Thread Starter Forum Replies Last Post
data reading from excel using VB.net fly2irfan VB Databases Basics 1 January 27th, 2008 02:35 AM
problem in reading excel data premnaath ASP.NET 2.0 Professional 5 October 22nd, 2007 10:14 AM
Reading and Writing data from Excel using VB? honey123 VB How-To 0 March 25th, 2006 08:48 AM
reading data from excel sheet rajiv_software Classic ASP Basics 2 April 30th, 2005 01:03 AM
Reading Values from Excel cell into VB 6 applicati pratlina Beginning VB 6 2 December 28th, 2004 08:28 AM





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