VBA to open a text file and load the contents into a string that is returned
Open the specified path\filename for reading. Use Input to write its contents to a string that can be returned.
'*************** Code Start ***************************************************** ' Purpose : Read the contents of a text file to a string ' Author : crystal (strive4peace) ' Return : String ' License : below code ' Code List: www.MsAccessGurus.com/code.htm '--------------------------------------------------------------------------------' ReadTextFile
'-------------------------------------------------------------------------------- Public Function ReadTextFile (psPathFile As String) As String '160730 strive4peace Dim iFile As Integer _ , sFileContents As String iFile = FreeFile Open psPathFile For Input As iFile sFileContents = Input(LOF(iFile), iFile) Close iFile ReadTextFile = sFileContents End Function ' ' LICENSE ' You may freely use and share this code ' provided this license notice and comment lines are not changed; ' code may be modified provided you clearly note your changes. ' You may not sell this code alone, or as part of a collection, ' without my handwritten permission. ' All ownership rights reserved. Use at your own risk. ' ~ crystal (strive4peace) www.MsAccessGurus.com '*************** Code End *******************************************************
Share with others ...
here's the link to copy:
https://MsAccessGurus.com/VBA/Code/File_ReadTextFile.htm