Sub ImportTextToExcel()
Dim fso As Object, FilesToOpen, TextSource As Object, TotalLines, Res()
Dim ItemsOfLine, TextItem, Des As Range, Delimiter
Dim k As Long, x As Byte, Cols As Integer, LineNum As Long
Set fso = CreateObject("Scripting.FileSystemObject")
Set Des = [A1]
Delimiter = "|"
FilesToOpen = Application.GetOpenFilename("Text Files (*.txt), *.txt", , , , True)
If Not IsArray(FilesToOpen) Then Exit Sub
For x = LBound(FilesToOpen) To UBound(FilesToOpen)
k = 0
Set TextSource = fso.OpenTextFile(FilesToOpen(x), 1, , -2)
TotalLines = Split(TextSource.ReadAll, vbCrLf)
ReDim Res(1 To 1 + UBound(TotalLines), 1 To 1)
For LineNum = LBound(TotalLines) To UBound(TotalLines)
ItemsOfLine = TotalLines(LineNum)
TextItem = Split(ItemsOfLine, Delimiter)
If UBound(Res, 2) < UBound(TextItem) + 1 Then
ReDim Preserve Res(1 To 1 + UBound(TotalLines), 1 To UBound(TextItem) + 1)
End If
If ItemsOfLine <> String(Len(ItemsOfLine), vbTab) Then
k = k + 1
For Cols = LBound(TextItem) To UBound(TextItem)
Res(k, Cols + 1) = TextItem(Cols)
Next
End If
Next
Des.Resize(k, UBound(Res, 2)) = Res
Set Des = Des.Offset(k)
Next
Rows("1:1").EntireRow.Delete
Rows("2:2").EntireRow.Delete
End Sub