I wan to open the txt file in excel using the below code...however it only can help me open without separate the comma, space into column in excel...how will be the code?
Please help!
Sub Import()
Open "d:\data.txt" For Input As #1
R = 1
While Not EOF(1) 'Scan file line by line
C = 1
Entry = ""
Line Input #1, Buffer
Length = Len(Buffer)
i = 1
While i <= Length 'split comma-delimited string into cells
If (Mid(Buffer, i, 1)) = "," Then
With Application.Cells(R, C)
.NumberFormat = "@" 'Text formatting
.Value = Entry
End With
C = C + 1
Entry = ""
Else
Entry = Entry + Mid(Buffer, i, 1)
End If
i = i + 1
Wend
If Len(Entry) > 0 Then
With Application.Cells(R, C)
.NumberFormat = "@" 'Text formatting
.Value = Entry
End With
End If
R = R + 1
Wend
Close #1
End Sub
Bookmarks