Read a text file into a string variable

The VBA code below shows how you can read a text file's content into a string variable in one go.


Dim strFilename As String: strFilename = "C:\temp\yourfile.txt"
Dim strFileContent As String
Dim iFile As Integer: iFile = FreeFile
Open strFilename For Input As #iFile
strFileContent = Input(LOF(iFile), iFile)
Close #iFile
Code VBA menu read text file contents into a string variable