Read text file : TextStream « File Path « VBA / Excel / Access / Word






Read text file

 
Public Sub ReadTxtFile()
    Dim myFileSystemObject As FileSystemObject
    Dim aFile As TextStream

    Set myFileSystemObject = New FileSystemObject
    Set aFile = myFileSystemObject.OpenTextFile("C:\myFile.txt", 1)

    Do While Not aFile.AtEndOfStream
        Debug.Print aFile.ReadLine
    Loop
    aFile.Close     'Close file and convert lines of data to columns
    Set myFileSystemObject = Nothing
    Set aFile = Nothing
End Sub

 








Related examples in the same category

1.The TextStream Object
2.On Error/Goto and the Err Object