I would like to loop through all Excel files in a folder in order to do something with each file (all files have the same layout and only data on Sheet1).
So far I have the following code which gives me a list of the Excel files in a specific folder. What I couldn't figure out myself is how I can copy data from each file - specifically I would need to copy the data in range A10:E50 from each file and then paste it on a page in my current file (all below each other).
Can someone help me with this ?
My current code:
Sub FindFiles()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim ws As Worksheet
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ws = Worksheets.Add
Set objFolder = objFSO.GetFolder("C:\Users\mo\Desktop\Test-Import\")
'ws.Cells(1, 1).Value = "The folder " & objFolder.Name & " contains the following Excel files:"
For Each objFile In objFolder.Files
ws.Cells(ws.UsedRange.Rows.Count + 1, 1).Value = objFile.Name
Next
Set objFolder = Nothing
Set objFile = Nothing
Set objFSO = Nothing
End Sub
Many thanks in advance for any help, Mike