Hi There,
I'm looking for macro that would read all text files from a specified folder (not subfolders).
The code should loop through all text files and complete 2 columns with filename and file content
column a: filename
column b: file content
I tried to start with a simple code below ... but guess I should use an FSO approach instead
Any recommendation or post page/post you could direct me to?
Sub TextImport()
Dim PathName As String
Dim FileNumber As Integer
Dim Textdata As String
'Path
PathName = "C:\FILE_LOCATION\database.txt"
FileNumber = FreeFile() 'Assigns the first available file number (E.g.: #1 )
Open PathName For Input As #FileNumber 'Open file in read mode
'Copy the contents to Worksheet ---
Textdata = Input(LOF(FileNumber), FileNumber) 'Loads all file contents into variable
Range("A1").Value = Application.Transpose(Textdata)
'----------------------------------
Close #FileNumber 'Closes the file (the number in FileNumber can be reused)
End Sub
I'm looking for macro that would read all text files from a specified folder (not subfolders).
The code should loop through all text files and complete 2 columns with filename and file content
column a: filename
column b: file content
I tried to start with a simple code below ... but guess I should use an FSO approach instead
Any recommendation or post page/post you could direct me to?
Sub TextImport()
Dim PathName As String
Dim FileNumber As Integer
Dim Textdata As String
'Path
PathName = "C:\FILE_LOCATION\database.txt"
FileNumber = FreeFile() 'Assigns the first available file number (E.g.: #1 )
Open PathName For Input As #FileNumber 'Open file in read mode
'Copy the contents to Worksheet ---
Textdata = Input(LOF(FileNumber), FileNumber) 'Loads all file contents into variable
Range("A1").Value = Application.Transpose(Textdata)
'----------------------------------
Close #FileNumber 'Closes the file (the number in FileNumber can be reused)
End Sub