|
Anthony's VBA Forum Where the knowledge is shared |
|
|
View previous topic :: View next topic |
Author |
Message |
bshaen
Joined: 10 Jan 2005 Posts: 9 Location: malaysia
|
Posted: Fri Jan 14, 2005 5:51 am Post subject: how can vb recogrite how many col we need to display?? |
|
|
test.txt
1 A A Flute 1.00 1.00 1.00
2 A1 A1 FLUTE 1.00 0.00 1.00
3 AB AB Flute /Double Wall 1.00 2.50 1.00
4 ABC ABC Flute /Triple Wall 1.00 2.50 1.00
5 ABF ABF 0.00 0.00 1.00
test1.txt
1 A A Flute 1.00 1.00
2 A1 A1 FLUTE 1.00 0.00
3 AB AB Flute /Double Wall 1.00 2.50
4 ABC ABC Flute /Triple Wall 1.00 2.50
5 ABF ABF 0.00 0.00
i have write a program which is about vba-excel, read the text file and display the data into excel format.
that have successful to run the program, but the problem is whether that is possible to use the single program that able to know how many column of particular taxt file i want to import, and width of each col? the program is not read 2 text file concurrently, that is depend on user what text file they want to execute.
With xlsheet.QueryTables.Add(Connection:="TEXT;\\Admin1\C\test.txt", _
Destination:=Range("A1"))
.TextFileParseType = xlFixedWidth
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(5, 16, 34, 5)
.Refresh
End With
**that is the coding i done for the text file, we already know how many col that we need.
the problem now is we should assume we don't know how many column need for each text file's data to display on excel. _________________ bshaen |
|
Back to top |
|
|
Data Moderator
Joined: 06 Oct 2004 Posts: 33 Location: NY
|
Posted: Fri Jan 14, 2005 11:31 am Post subject: |
|
|
Don't think too complicated. If your text file in delimited (ex: by space), you can that your program count how many spaces you have in the line of string. The number of space + 1 is your columns number. _________________ Data
Knowledge is Power
Last edited by Data on Mon Jan 17, 2005 12:19 am; edited 1 time in total |
|
Back to top |
|
|
bshaen
Joined: 10 Jan 2005 Posts: 9 Location: malaysia
|
Posted: Sun Jan 16, 2005 9:32 pm Post subject: |
|
|
how the coding i can apply???
casue i know
.TextFileConsecutiveDelimiter = True
but i don't know how to specific to 2 space??? can u give me some idea of it? thank _________________ bshaen |
|
Back to top |
|
|
Data Moderator
Joined: 06 Oct 2004 Posts: 33 Location: NY
|
Posted: Mon Jan 17, 2005 12:21 am Post subject: |
|
|
You can use the [b]instring[/b] function in VB that break the string into array. By counting how many arrays in generated in the string, you get the columns. _________________ Data
Knowledge is Power |
|
Back to top |
|
|
bshaen
Joined: 10 Jan 2005 Posts: 9 Location: malaysia
|
Posted: Mon Jan 17, 2005 12:52 am Post subject: |
|
|
sorry, can u futher explain of the instring function with example??? _________________ bshaen |
|
Back to top |
|
|
Djamanbe Guest
|
Posted: Wed Mar 29, 2006 5:58 pm Post subject: Excel Parser |
|
|
Thanks a lot Anthony for your clean parser example.
Jean-Marc |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2002 phpBB Group
|