Sub ImportTextFilesMacro_rapidasia()
'Change the folder path as needed
Const strFolderPath As String = "C:\Test"
'Declare variables
Dim FSO As Object 'Used to access the Windows FileSystem
Dim strFileName As String 'Used to store the filename
Dim arrText(1 To 65000) As String 'Used to store the .txt file's text
Dim TextIndex As Long 'Used by arrText for storing the text in the correct location
'Access the Windows FileSystem
Set FSO = CreateObject("Scripting.FileSystemObject")
'Use the folderpath to find all the first .txt file in that folder
strFileName = Dir(strFolderPath & "\*.txt")
'Loop through all the text files
Do While Len(strFileName) > 0
'Found a text file, increase the TextIndex
TextIndex = TextIndex + 1
'Use the Windows FileSystem to read the text file and store that information in arrText
arrText(TextIndex) = FSO.OpenTextFile(strFolderPath & "\" & strFileName).ReadAll
strFileName = Dir 'Advance the loop
Loop
'If at least 1 text file was found, output the results in column C
If TextIndex > 0 Then Range("C1").Resize(TextIndex).Value = Application.Transpose(arrText)
'Cleanup objects and arrays
Set FSO = Nothing
Erase arrText
End Sub
Bookmarks