It is hard to give code without seeing the data. The 1st thing I would try
is importing the data Using Data - Import External Data - Extternal Data and
see if this reads the data properly.
If this works, the capture the command by go to Tools Macro - Record New
Macro. the recorded macro can be used in your code.
Here is an example of a file that reads and writes text data. It doesn't
have code that puts data into the cells. It simply converts text data into
CSV. Then the CSV can be read into Excel
I'm very good at working with text files and will be glad to give you more
help. You request is very vague and really need to know more about the data
to give you a bettter answer.
Sub Gettext()
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const MyPath = "C:\temp\"
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Set fsread = CreateObject("Scripting.FileSystemObject")
Set fswrite = CreateObject("Scripting.FileSystemObject")
ReadFileName = "longtext.txt"
WriteFileName = "longtext.csv"
'open files
ReadPathName = MyPath + ReadFileName
Set fread = fsread.GetFile(ReadPathName)
Set tsread = fread.OpenAsTextStream(ForReading, TristateUseDefault)
WritePathName = MyPath + WriteFileName
fswrite.CreateTextFile WritePathName
Set fwrite = fswrite.GetFile(WritePathName)
Set tswrite = fwrite.OpenAsTextStream(ForWriting, TristateUseDefault)
Do While tsread.atendofstream = False
InputLine = tsread.ReadLine
If (InStr(InputLine, "TEXT") > 0) Then
If Len(OutputLine) > 0 Then
tswrite.WriteLine OutputLine
OutputLine = ""
End If
Else
If Len(OutputLine) > 0 Then
OutputLine = OutputLine + "," + InputLine
Else
OutputLine = InputLine
End If
End If
Loop
tswrite.Close
tsread.Close
Exit Sub
End Sub