Thread
:
Importing Text File into Excel loses leading zero on some fields.
View Single Post
#
2
Posted to microsoft.public.excel.programming
Dave Peterson
external usenet poster
Posts: 35,218
Importing Text File into Excel loses leading zero on some fields.
Try recording a macro when you open that text file manually. But make sure you
change the field to Text.
Or if you want to keep that field a number, you could keep it General, but then
apply the numberformat in your code.
wrote:
Hello,
Is it possible to import a txt file into Excel and keep the leading
zero's? I am using vbscript to import the text file, the text file
contains a user reference which sometimes contains a number with a
leading zero i.e. 0111. This number is imported as 111. The user
reference varies sometimes so I cannot really use a custom field i.e.
"0"#.
Below is an example of the import procedure I am using, is it possible
to specify that for example column L is displayed as text?
Range("FileOrig").FormulaR1C1 = FILEtoOPEN
Workbooks.OpenText Filename:=FILEtoOPEN, Origin:= _
xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier _
:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, _
FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1),
Array(4, 1), Array _
(5, 4), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1),
Array(10, 1), Array( _
11, 1), Array(12, 1), Array(13, 1))
Range("A1:AZ1500").Select
Selection.Copy
Thanks,
Brett
--
Dave Peterson
Reply With Quote
Dave Peterson
View Public Profile
Find all posts by Dave Peterson