excel truncating leading zeros

V

Veena

Hi,

I am trying to use the import from text file into an excel sheet. I
read many queries and figured out how to import the values as text
without dropping the leading zeros.
Please suggest a way where i can import all the values as "text" type.
I want to avoid creating an array as the size of my text file varies
from time to time.
So i will not be sure how big the array must be.

Please suggest.
Thanks .
regards,
veena.
 
E

ElsiePOA

In Step 3 on the Text Import Wizzard, select "text" in the upper righ
hand corner of the screen
 
J

Jim Rech

You can specify an array of the maximum size, 256 columns, and files with
fewer fields can still use it ignoring the extra array elements:

Sub ImportAnyNumberOfFieldsAsText()
Dim Counter As Integer
Dim FieldInfoArray(1 To 256, 1 To 2) As Integer
For Counter = 1 To 256
FieldInfoArray(Counter, 1) = Counter
FieldInfoArray(Counter, 2) = 2
Next
Workbooks.OpenText Filename:="C:\test.txt", _
DataType:=xlDelimited, Comma:=True, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter _
:=False, FieldInfo:=FieldInfoArray
End Sub


--
Jim Rech
Excel MVP
| Hi,
|
| I am trying to use the import from text file into an excel sheet. I
| read many queries and figured out how to import the values as text
| without dropping the leading zeros.
| Please suggest a way where i can import all the values as "text" type.
| I want to avoid creating an array as the size of my text file varies
| from time to time.
| So i will not be sure how big the array must be.
|
| Please suggest.
| Thanks .
| regards,
| veena.
 
Top