Hi im using the below code to read in textfiles and then displaying various results from the files on an excel spreadsheet.Ive managed to get it reading in files and displaying data however it browses the folder and only displays the data from the last file what am i doing wrong?
Cheers
Public Sub readDataFromFile()
Dim myFile As String
Dim FF As Integer
Dim temp As String
Dim r As Integer
Dim fso As Object
Dim fld As Object
Dim fileN As Object
Dim foldername As String
Dim x As Integer
Dim y As Integer
Dim GetLine As String
Set myBook = ActiveWorkbook
Set mysheet = myBook.Sheets(1)
x = 0
Set fso = CreateObject("scripting.FileSystemobject"
myFile = "DIRECTORY"
Set fld = fso.GetFolder(myFile)
For Each fileN In fld.Files
i = FreeFile
Open fileN For Input As #i
Do While Not EOF(i)
Line Input #i, GetLine
' Code to extract data goes here
Loop
Close #i
End Sub
Cheers
Public Sub readDataFromFile()
Dim myFile As String
Dim FF As Integer
Dim temp As String
Dim r As Integer
Dim fso As Object
Dim fld As Object
Dim fileN As Object
Dim foldername As String
Dim x As Integer
Dim y As Integer
Dim GetLine As String
Set myBook = ActiveWorkbook
Set mysheet = myBook.Sheets(1)
x = 0
Set fso = CreateObject("scripting.FileSystemobject"
myFile = "DIRECTORY"
Set fld = fso.GetFolder(myFile)
For Each fileN In fld.Files
i = FreeFile
Open fileN For Input As #i
Do While Not EOF(i)
Line Input #i, GetLine
' Code to extract data goes here
Loop
Close #i
End Sub