Use the FileSystemObject that is part of the Microsoft Scripting Runtime (scrrun.dll)
You can use something like -
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
Also have a look at this link with an attached sample...
AndreRet
Industrious Poster
4,706 posts since Jan 2008
Reputation Points: 391
Solved Threads: 481
Skill Endorsements: 20
TnTinMN
Practically a Master Poster
640 posts since Jun 2012
Reputation Points: 418
Solved Threads: 148
Skill Endorsements: 13