Sub MergeSelectedWorkbooks()
Dim Ws_Out As Worksheet
Dim Percorso As String
Dim File_Selezionati() As Variant
Dim Num_Riga As Long
Dim FileName As String
Dim NFile As Long
Dim WB As Workbook
Dim Intervallo_In As Range
Dim Intervallo_Out As Range
Set Ws_Out = ActiveWorkbook.Sheets(1)
Percorso = "\\\\\\\\\\" ' <<===== INSERIRE IL PERCORSO
ChDrive Percorso
ChDir Percorso
File_Selezionati = Application.GetOpenFilename( _
filefilter:="Excel Files (*.xl*), *.xl*", MultiSelect:=True)
Num_Riga = 2
For NFile = LBound(File_Selezionati) To UBound(File_Selezionati)
FileName = File_Selezionati(NFile)
Set WB = Workbooks.Open(FileName)
Ws_Out.Range("A" & Num_Riga).Value = FileName
UR = WB.Worksheets(2).Range("A" & Rows.Count).End(xlUp).Row ' <<===== AGGIUNTA
Set Intervallo_In = WB.Worksheets(2).Range("A5:F" & UR) ' <<===== Intervallo dati del "PRIMO FOGLIO" da copiare
Set Intervallo_Out = Ws_Out.Range("B" & Num_Riga)
Set Intervallo_Out = Intervallo_Out.Resize(Intervallo_In.Rows.Count, _
Intervallo_In.Columns.Count)
Intervallo_Out.Value = Intervallo_In.Value
Num_Riga = Num_Riga + Intervallo_Out.Rows.Count
WB.Close savechanges:=False
Next NFile
Ws_Out.Columns.AutoFit
End Sub