Click here to Skip to main content
14,669,432 members
Rate this:
Please Sign up or sign in to vote.
See more:
Sub ReadLineByLine()
    Dim strLine As String
    Dim oFS As Object
    Dim oTS As Object
    Dim lineNumber As Integer
    Set oFS = CreateObject("Scripting.FileSystemObject")
    Set oTS = oFS.OpenTextFile("C:\SYDNEY ERS_121713.txt")
    Do While oTS.AtEndOfStream = False
        strLine = oTS.Readline
        Dim Item1 As String
        Dim RowItm As Long
        RowItm = Range("A65536").End(xlUp).Row + 1
        ColItm = "A" & RowItm
        Item1 = Mid(strLine, 3, 23)
        Range(ColItem).Value = Item1 ' Error Occurs here!
    Set oTS = Nothing
    Set oFS = Nothing
End Sub

I do not know why that error occurs. I have debugged it many times already. Help. :(

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Have a look at MS Excel OpenText[^] method. It loads and parses a text file as a new workbook with a single sheet that contains the parsed text-file data.

I would suggest you to record macro ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100