Importing Text Files

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When importing a comma-delimited .txt file, are there any settings that can
be made so that Excel automatically recognizes all leading zeros in fields?
I am now going through the import wizard and changing the format from general
to text for all fields that I can recognize that have leading zeros but this
is cumbersome.
 
No.

But if you're always importing files with the same layout, you could record a
macro when you import one of these files.

Do all the stuff you want during the import, but keep recording when you add
headers/page setup/filters/subtotals/whatever.

Then when you need to open the next file, just rerun the macro.

You could even ask the user (you???) for the name of the file to import:

Option Explicit
Sub testme()

Dim myFileName As Variant

myFileName = Application.GetOpenFilename(filefilter:="Text Files, *.Txt", _
Title:="Pick a File")

If myFileName = False Then
MsgBox "Ok, try later" 'user hit cancel
Exit Sub
End If

Workbooks.OpenText Filename:=myFileName '....rest of recorded code here!

End Sub

You'll have to add all that .opentext stuff from your recorded macro.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
 
Back
Top