An alternative to the FileSystemObject
would be ADO
However, your statement
I (believe) you're loading into memory the WHOLE thing only to read
the first few characters.
is wrong.
What I think is misleading you is the fact that you are not exiting the loop after you read the first line. You get what you want by reading line by line but you are not closing the file right away. It's a good programmers practice to always close any objects you initiate in your code. Don't just leave it hanging and don't rely on the environment to kill them.
Consider the below code as an alternative to yours and see if there is any efficiency difference
Option Explicit
' add references to Microsoft Scripting Runtime
' Tools >> References >> Microsoft Scripting Runtime
Sub Main()
Dim fileName As String
' make sure to update your path
fileName = "C:\Users\FoohBooh\Desktop\Project.txt"
ReadTxtFile fileName
End Sub
Sub ReadTxtFile(fileName)
Dim oFSO As New FileSystemObject
Dim oFS As TextStream
Set oFS = oFSO.OpenTextFile(fileName)
Dim content As String
content = oFS.ReadLine
With Sheets(1).Range("A1")
.ClearContents
.NumberFormat = "@"
.Value = content
End With
oFS.Close
Set oFS = Nothing
End Sub
The above code reads the first line of a .txt file into cell A1 of the first sheet. Remember to set a fileName variable to a full path.