Option Explicit
Function import_report()
Dim wbk As Workbook, wbk_dest As Workbook
Dim my_path As String, fso As Object, f As Object, i As Integer
my_path = "path & filename here.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set wbk_dest = ThisWorkbook
i = 1
For Each f In fso.getFolder(my_path).Files
Set wbk = Workbooks.Open(f)
If wbk.Sheets("report").[A1].CurrentRegion.Rows.Count - 1 > 0 Then
wbk.Sheets("report").[A1].CurrentRegion.Offset(1).Resize(wbk.Sheets("report").[A1].CurrentRegion.Rows.Count - 1).Copy wbk_dest.Sheets("report").[A1].Offset(i)
i = i + wbk.Sheets("report").[A1].CurrentRegion.Rows.Count - 1
End If
wbk.Close False
Next
MsgBox "Fatto."
End Function |