I don't often find occasions to read txt files, but recently such an occasion arose
Not sure what your recent occasion entailed but just wanted to point out that FileSystemObject has a text stream object which is pretty handy.
Code:
Sub OpenTextFileRead(sTextFilePath As String)
' Must add reference to Tools > References > Microsoft Scripting Runtime
' (1) Open an instance of the FileSystemObject.
' (2) Open an instance of the FileSystemObject TextStream.
' (3) Read each line of text in the TextStream object.
' (4) Close the TextStream object.
Dim fso As Scripting.FileSystemObject
Dim tsTxtFile As Scripting.TextStream
' (1) Open an instance of the FileSystemObject.
Set fso = New Scripting.FileSystemObject
' (2) Open an instance of the FileSystemObject TextStream.
Set tsTxtFile = fso.OpenTextFile(sTextFilePath, ForReading, False, TristateMixed)
With tsTxtFile
' (3) Read each line of text in the TextStream object.
Do Until .AtEndOfStream
' ************************************
' insert your code here
' ************************************
Debug.Print .Line & ": " & .ReadLine ' remove in production
Loop
' (4) Close the TextStream object.
.Close
End With
Set fso = Nothing
End Sub
5 test lines with a CrLf after each entry.
Code:
1: test line 1
2:
3: test line 2
4:
5: test line 3
6:
7: test line 4
8:
9: test line 5
10: