| | |
Open and Read MS Excel Files
![]() |
•
•
Join Date: Jul 2009
Posts: 1
Reputation:
Solved Threads: 0
Greetings,
Here is my Problem.
I have written a VB6 program that works just fine. I wrote it with all of my Variable Arrays written within the program itself. This has made the program very long and I would like to shorten it. I have the Arrays also written in a MS Excel Workbook File with each Worksheet a different file.
What I would like to do is have a routine to open the Excel Workbook and then Read into the VB Program each of the Worksheets. Some of the Worksheet contains Numerical Values with the remaining have Test Values. The Arrays Dimensions will range from Array(x) to Array(x,y,z). I now that I can set up the Reading of the Dimensions using the Do/For Routine. What I do not know how to do is Open the Excel File and the Reading of the File Code needed in the VB Program.
One last Question is it possible to have the Array’s Dimensions in the VB Program set as a Dynamic Number. The “X” Dimension in each of the files will change as the Files are updated. The “Y” and “Z” Dimensions will always remain constant but it is the “X” that will change. So, is there a way to have the “X” Dimension in the VB part be Declared after the File is Read from the Excel Worksheet?
Thanks,
Beatle Bailey
Here is my Problem.
I have written a VB6 program that works just fine. I wrote it with all of my Variable Arrays written within the program itself. This has made the program very long and I would like to shorten it. I have the Arrays also written in a MS Excel Workbook File with each Worksheet a different file.
What I would like to do is have a routine to open the Excel Workbook and then Read into the VB Program each of the Worksheets. Some of the Worksheet contains Numerical Values with the remaining have Test Values. The Arrays Dimensions will range from Array(x) to Array(x,y,z). I now that I can set up the Reading of the Dimensions using the Do/For Routine. What I do not know how to do is Open the Excel File and the Reading of the File Code needed in the VB Program.
One last Question is it possible to have the Array’s Dimensions in the VB Program set as a Dynamic Number. The “X” Dimension in each of the files will change as the Files are updated. The “Y” and “Z” Dimensions will always remain constant but it is the “X” that will change. So, is there a way to have the “X” Dimension in the VB part be Declared after the File is Read from the Excel Worksheet?
Thanks,
Beatle Bailey
•
•
Join Date: Mar 2009
Posts: 810
Reputation:
Solved Threads: 147
Okay, several way in which to do this but let me start at the bottom and work my way up...
Yes it is possible to redimension arrays based upon a variable value...
Now, as for accessing an excel file there are several ways. You can use ADO and treat it like a database and return your data in a recordset. See http://www.connectionstrings.com for connection string information if you need it or you can search the www at your favorite search engine for vb6 excel and you will find many examples out there.
Good Luck
Yes it is possible to redimension arrays based upon a variable value...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Dim MyArray() As Integer Dim MyValue As Integer MyValue = 10 ReDim MyArray(MyValue) As Integer Debug.Print UBound(MyArray)
Now, as for accessing an excel file there are several ways. You can use ADO and treat it like a database and return your data in a recordset. See http://www.connectionstrings.com for connection string information if you need it or you can search the www at your favorite search engine for vb6 excel and you will find many examples out there.
Good Luck
If anyone has helped you solve your problem, please mark your thread as solved.
Thanks
Thanks
Check the following thread. I have written some code. May be of some help. If not then u may post back for further requirement stating some sample data.
http://www.daniweb.com/forums/thread139729.html
http://www.daniweb.com/forums/thread139729.html
Regards
Shaik Akthar
Shaik Akthar
•
•
Join Date: May 2009
Posts: 11
Reputation:
Solved Threads: 0
As an example use this.
DO NOT USE THIS - Dim mExcel as Excel.Application
it's no good if you wish to distribute your application
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Dim objExcel As Object Dim objWorkBook As Object Dim mArray() As String Set objExcel = CreateObject("EXCEL.APPLICATION") Set objWorkBook = objExcel.Workbooks.Open("C:\test\test.xls") Dim intCount As Integer intCount = objWorkBook.Worksheets.Count ReDim mArray(intCount - 1) For intCount = 1 To objWorkBook.Worksheets.Count mArray(intCount - 1) = objWorkBook.Worksheets(intCount).Name Debug.Print mArray(intCount - 1) Next objWorkBook.Close True Set objWorkBook = Nothing objExcel.Quit Set objExcel = Nothing
DO NOT USE THIS - Dim mExcel as Excel.Application
it's no good if you wish to distribute your application
Last edited by tonym001; Jul 24th, 2009 at 5:55 pm.
![]() |
Similar Threads
- open and read all files from folder (Java)
- How to open and read a multi files in? (C++)
- retreive data from excel files (C++)
- Cannot open Excel Files anymore!! (Windows NT / 2000 / XP)
- Create modify insert del read from excel file (C++)
- problem with Sendkeys (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: incrementing the number
- Next Thread: Sql Statement issue
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





