Robert2100
New Member
- Joined
- May 26, 2003
- Messages
- 38
I'd like to extract data from a CSV file which has no header.
The consequence of this is that the first row is always different every time the data file is created.
Can I refer to columns generically (eg. Column1, Column2 etc...)?
My trial code to extract the first column from the CSV file "Bob.txt" is below. You can see that following the SELECT statement there is some date/time data. In this particular file this is the first entry.
vSQLStrTime = "SELECT Bob.`2005/05/20 11:27:12`"
How do I make this column reference generic?
Your help would be appreciated.
The consequence of this is that the first row is always different every time the data file is created.
Can I refer to columns generically (eg. Column1, Column2 etc...)?
My trial code to extract the first column from the CSV file "Bob.txt" is below. You can see that following the SELECT statement there is some date/time data. In this particular file this is the first entry.
vSQLStrTime = "SELECT Bob.`2005/05/20 11:27:12`"
How do I make this column reference generic?
Your help would be appreciated.
Code:
vPathName = "C:\Documents and Settings\User\Desktop;"
vArrayStr = "ODBC;DefaultDir="
vArrayStr = vArrayStr & vPathName
vArrayStr = vArrayStr & ";Driver={Microsoft Text Driver(*.txt; .csv)};DriverId=27;FIL=text;Ma"
'Build SQL String
vSQLStrTime = "SELECT Bob.`2005/05/20 11:27:12`"
vSQLStrTime = vSQLStrTime & Chr(13) & "" & Chr(10)
vSQLStrTime = vSQLStrTime & "FROM Bob.txt Bob"
With ActiveSheet.QueryTables.Add(Connection:=Array(Array(vArrayStr)), Destination:=Range("A1"))
.CommandText = Array(vSQLStrTime)
.Name = "QueryArbinResults"
.FieldNames = False
.RefreshStyle = xlOverwriteCells
.Refresh BackgroundQuery:=False
End With