Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA 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 March 2nd, 2005, 11:41 AM
Registered User
 
Join Date: Mar 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default expporting data from a Excel file and showing it

how can i do this?

first i have to create a excel object right?

and then what?





 
Old March 2nd, 2005, 12:13 PM
Registered User
 
Join Date: Mar 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

importing.. sorry


 
Old March 2nd, 2005, 12:48 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

A little more details ´what are you doing. Importing from etc.



 
Old March 2nd, 2005, 01:03 PM
Registered User
 
Join Date: Mar 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I´m trying to import an excel sheet with "n" rows and 2 columns into variables inside vb 6...

i´m trying to do a sort of select ( sql style) , that´s why i need to import the data from the excel sheet...



 
Old March 2nd, 2005, 02:01 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

You must first set reference to Microsoft Excel library

Here is an example how to read Excel table to an array

Sub Load_Data()
Dim xlApp As Excel.Application
Dim Table
Set xlApp = New Excel.Application
xlApp.Workbooks.Open FileName:="File.xls"
'*** Takes whole table to an array
Table = xlApp.ActiveSheet.Range("A1").CurrentRegion
xlApp.Quit
Set xlApp = Nothing
End Sub


-vemaju


 
Old March 2nd, 2005, 02:17 PM
Registered User
 
Join Date: Mar 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

but that code sample only works for one collumn right?

 
Old March 2nd, 2005, 02:22 PM
Registered User
 
Join Date: Mar 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

for example:


i have the following excel table for e.g.:

user Id | number
----------------
1 | 0
1 | 2
2 | 1


and i want to return the data referent to the user with id=1

for eg:

select *
from table
where userId =1

How can I transcribe this into Vb???

But then i want to set the results of this select into some variables...

 
Old March 3rd, 2005, 10:17 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What are you doing with the data once it's in VB6?


 
Old March 4th, 2005, 05:51 PM
Authorized User
 
Join Date: Feb 2005
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,

without opening the workbook with the worksheet u need data from, try this:

path = [path where the file is located] (with \ at the end)
filename= [workbook where data has to be collected]
sheetname = [sheet from worbook with data]
'
string = "'" & path & "[" & filename & "]" & sheetname & "'!" & "r" & i & "c" & j
(i represents the row, j represents the column)
value = ExecuteExcel4Macro(string)

put this piece of code in a loop and your done





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read data from an excel file diegoblin Beginning VB 6 6 August 31st, 2009 11:04 PM
Read Data from Excel File kiwibey ASP.NET 2.0 Professional 1 December 5th, 2006 11:27 AM
Creating an excel file and showing on the form dotnetprogrammer C# 0 May 3rd, 2005 07:36 AM
How to get data in an excel file ? stevenThu Classic ASP Databases 0 September 3rd, 2003 09:03 PM





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