Simo Bk
07-08-2008, 08:01 AM
Hi,
I am trying to import a text file that has a structure that's basically like this :
TITLE
2 45 18
COL1 COL2 COL3 COL4
aaa 000 11 222
bbbbb 33 4444 5
I use the following code to import it :
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;D:\test.txt", _
Destination:=Range("A1"))
.Name = "test"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 2, 2, 2)
.TextFileFixedColumnWidths = Array(8, 10, 9)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
And then recreate the split headers like this :
Range("E1") = Range("A1").Value & Range("B1").Value
Range("E2") = Range("A2").Value & Range("B2").Value
Here is the result I get :
http://www.simo-multimedia.com/tmp/vbaImport.jpg
If you compare the re-generated title in column E2, you can see that it went from 2 45 18 to 245 18
How can I make it so it doesnt get rid of the preceeding and trailing spaces on import, so I don't have this problem?
Thank you,
Simo
I am trying to import a text file that has a structure that's basically like this :
TITLE
2 45 18
COL1 COL2 COL3 COL4
aaa 000 11 222
bbbbb 33 4444 5
I use the following code to import it :
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;D:\test.txt", _
Destination:=Range("A1"))
.Name = "test"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 2, 2, 2)
.TextFileFixedColumnWidths = Array(8, 10, 9)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
And then recreate the split headers like this :
Range("E1") = Range("A1").Value & Range("B1").Value
Range("E2") = Range("A2").Value & Range("B2").Value
Here is the result I get :
http://www.simo-multimedia.com/tmp/vbaImport.jpg
If you compare the re-generated title in column E2, you can see that it went from 2 45 18 to 245 18
How can I make it so it doesnt get rid of the preceeding and trailing spaces on import, so I don't have this problem?
Thank you,
Simo