Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
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!
        
    Loop
     
     
    oTS.Close
    Set oTS = Nothing
    Set oFS = Nothing
     
End Sub


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

1 solution

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 ;)
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900