When you work with a Stream object, I think it is obvious that .LoadFromFile fills the current stream with the full contents of the file and does not have any cutomize option to load parial data from the file.
As for reading 1 line, you already did this with .ReadText(-2) , (-2 = adReadLine).
Set objStream = CreateObject("ADODB.Stream") objStream.Charset = "utf-8" objStream.Type = 2 objStream.Open 'objStream.LoadFromFile = strFile ''I see a typo here objStream.LoadFromFile strFile objStream.LineSeparator = 10 ''that Ok 'Do Until objStream.EOS ''no need this strLine = objStream.ReadText(-2) 'Loop objStream.Close ''add this though!
[ EDIT ] Well, for . LineSeparator you can use only 3 constants:
Constant Value Description adCRLF -1 Default. Carriage return line feed adLF 10 Line feed only adCR 13 Carriage return only
If you need to split Do..Loop into another letter, since .ReadText is the only choice for reading a text stream, you can use it in combination with the InStr and Exit Do functions, after which you will find your custom separator.
Const cSeparator = "_" 'your custom separator Dim strLine, strTotal, index Do Until objStream.EOS strLine = objStream.ReadText(-2) index = InStr(1, strLine, cSeparator) If index <> 0 Then strTotal = strTotal & Left(strLine, index-1) Exit Do Else strTotal = strTotal & strLine End If Loop
In short, this is all the optimization you can do (or at least as far as I know).
source share