I'm using the following code to import data stored in a .txt file into an Excel (XP) file:
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & Filename, Destination:=Range("A8"))
.FieldNames = True
.PreserveFormatting = True
.RefreshStyle = xlInsertDeleteCells
.SaveData = True
.AdjustColumnWidth = False
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTabDelimiter = True
.Refresh BackgroundQuery:=False
End With
The data looks like this:
0054632 0.03
0056434 0.016
0056650 0.207
Although the values in the first column are all numeric, they need to be imported as text in order to keep the leading zeros. Unfortunately, when I run the code, it brings in the data and removes the leading zeros. The number formatting of the cells where the data is imported into are set to text.
Does anyone know why Excel is not seeing these values as text and removing the leading zeros; also, is there a way to fix this?
Thanks!
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & Filename, Destination:=Range("A8"))
.FieldNames = True
.PreserveFormatting = True
.RefreshStyle = xlInsertDeleteCells
.SaveData = True
.AdjustColumnWidth = False
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTabDelimiter = True
.Refresh BackgroundQuery:=False
End With
The data looks like this:
0054632 0.03
0056434 0.016
0056650 0.207
Although the values in the first column are all numeric, they need to be imported as text in order to keep the leading zeros. Unfortunately, when I run the code, it brings in the data and removes the leading zeros. The number formatting of the cells where the data is imported into are set to text.
Does anyone know why Excel is not seeing these values as text and removing the leading zeros; also, is there a way to fix this?
Thanks!