Option Explicit
Sub duplica()
Dim fso As Object, fo As String, i As Integer, j As Integer
Dim excelfile As Object, wb As Object
Set fso = CreateObject("scripting.filesystemobject")
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Seleziona la cartella con i file Excel"
If .Show = 0 Then Exit Sub
fo = .SelectedItems(1)
End With
Application.ScreenUpdating = False
j = fso.getfolder(fo).Files.Count
For Each excelfile In fso.getfolder(fo).Files
Application.StatusBar = "Restano " & j & " files da esaminare..."
i = InStrRev(excelfile, ".")
If Mid(excelfile, i + 1) Like "xls*" Then
Set wb = Workbooks.Open(excelfile)
With wb
.Sheets("Foglio2").Copy After:=.Sheets(.Sheets.Count)
.Sheets(.Sheets.Count).Name = "Foglio" & .Sheets.Count
End With
wb.Close True
End If
j = j - 1
Next
Application.StatusBar = ""
Application.ScreenUpdating = True
Set excelfile = Nothing
Set fso = Nothing
MsgBox "Tutto fatto."
End Sub |