This macro will load in all the text files in the directory noted, edit to your path where the text files are stored. It will also parse out the data to separate columns. IF you don't want that, remove the blue code noted near the bottom:
Option Explicit
Sub ImportTextFile()
'JBeaucaire (11/10/2009)
'Loads all text files in a folder into column A
'then splits the data based on space-delimitation
Dim FName As String, fPath As String
Dim OldDir As String, MyStr As String
Dim NR As Long, i As Long
Application.ScreenUpdating = False
Application.DisplayAlerts = False
NR = 1
OldDir = CurDir 'memorizes the user's current working path
ChDir "C:\My Documents\Excel\TextFiles"
FName = Dir("*.txt")
Do While Len(FName) > 0
Open FName For Input Access Read As #1
Do While Not EOF(1)
Line Input #1, MyStr
If Left(MyStr, 1) <> "%" Then
Range("A" & NR) = MyStr
NR = NR + 1
End If
Loop
Close #1
FName = Dir
Loop
'Cleanup
Columns("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=True, Other:=False, FieldInfo _
:=Array(Array(1, 2), Array(2, 1), Array(3, 1), Array(4, 3), Array(5, 1), Array(6, 1)), _
TrailingMinusNumbers:=True
Cells.Columns.AutoFit
Application.ScreenUpdating = True
Application.DisplayAlerts = True
ChDir OldDir 'restores user's original working path
End Sub
Bookmarks