Ciao Red Mud,
Prova qualcosa del genere:
- Alt-F11 per aprire l'editor di VBA
- Alt-IM per inserire un nuovo modulo di codice
- Nel nuovo modulo vuoto, incolla il seguente codice:
'=========>>
Option Explicit
'--------->>
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet, destSH As Worksheet
Dim Rng As Range, rCell As Range
Dim arrExclude As Variant, arrFolders As Variant, arrHeaders As Variant
Dim iRow As Long
Dim i As Long, j As Long
Dim myFile As String
Dim Res As Variant
Const sAddress = "F2,K2,C4"
Const sFolders As String = "**C:\Pippo,C:\Pluto,C:Cat,C:\Dog**" '<<=== Modifica
Const sHeaders As String = "File di Origine,Foglio di Origine,Cliente,Data,Descrizione"
Set WB = ThisWorkbook
Set destSH = WB.Sheets(1)
iRow = 1
arrExclude = VBA.Array("Calcolo peso", "Forme")
arrFolders = Split(sFolders, ",")
arrHeaders = Split(sHeaders, ",")
destSH.Range("A1:E1").Value = arrHeaders
On Error GoTo XIT
Application.ScreenUpdating = False
For i = LBound(arrFolders) To UBound(arrFolders)
If Right(arrFolders(i), 1) <> Application.PathSeparator Then
arrFolders(i) = arrFolders(i) & Application.PathSeparator
End If
myFile = Dir(arrFolders(i))
Do While myFile <> ""
Set WB = Workbooks.Open(arrFolders(i) & myFile)
With WB
For Each SH In WB.Worksheets
With SH
j = 1
Res = Application.Match(.Name, arrExclude, 0)
If IsError(Res) Then
iRow = iRow + 1
With destSH
.Cells(iRow, "A").Value = WB.FullName
.Cells(iRow, "B").Value = SH.Name
Set Rng = SH.Range(sAddress)
For Each rCell In Rng.Cells
j = j + 1
.Cells(iRow, j + 1).Value = rCell.Value
Next rCell
End With
End If
End With
Next SH
.Close savechanges:=False
End With
myFile = Dir()
Loop
Next i
destSH.UsedRange.EntireColumn.AutoFit
XIT:
Application.ScreenUpdating = True
End Sub
'<<=========
- Alt-Q per chiudere l'editor di VBA e tornare a Excel.
- Alt-F8 per aprire la finestra di gestione delle macro
- Seleziona Tester | Esegui
===
Regards,
Norman