To read a textfile in VBA you can use the following snippet.
to read a textfile line by line see How to read a textfile line by line in VBA.

Sample VBA

Function ReadTextfileComplete(ByVal strFile As String) As String
Dim hFile As Long
    hFile = FreeFile
    Open strFile For Input As #hFile
    ReadTextfileComplete = Input$(LOF(hFile), hFile)
    Close #hFile
End Function

One thought on “How to read a textfile in VBA”

Leave a Reply