I'm a little late to the game here, but FileSystemObject, which is part of Microsoft Scripting Runtime (scrrun.dll), can be very useful for this.
Public Function ReadTextFileAsString(IN_sFilePath As String) As String Dim myFSO As Scripting.FileSystemObject Dim myTextStream As Scripting.TextStream Dim myString As String 'Create a new FileSystemObject Set myFSO = New Scripting.FileSystemObject 'Make sure file exists: If myFSO.FileExists(IN_sFilePath) Then Set myTextStream = myFSO.OpenTextFile(IN_sFilePath, ForReading) myString = myTextStream.ReadAll() Call myTextStream.Close End If 'Assign Return Value ReadTextFileAsString = myString 'Make sure to clean up when done. Set myTextStream = Nothing Set myFSO = Nothing End Function
There are many other methods for retrieving data from a text stream. You can also read a certain number of characters at a time or in turn. You will need to add Microsoft Scripting Runtime Runtime to your project links, but it is really very useful.
nedmech
source share