Getting text file into a VBA string variable


Sub Tester4()
 Dim fname As String
 Dim sVal As String
 fname = "C:\test\test.txt"
 sVal = OpenTextFileToString2(fname)
 Debug.Print sVal
 End Sub



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