Allora...
Parti da un nuovo file vuoto; metti in un nuovo Modulo standard del vba la seguente macro:
- Codice: Seleziona tutto
Sub myImport()
Dim wDir As String, sDir As String, myFile As String, fSo As Object, fCnt As Long
Dim myNext As Long, destSh As Worksheet, DPlex As Boolean, NName As String
'
wDir = "C:\Users\UTENTE\PercorsoCompleto\" '<<< La directory con i file da importare, con \ finale
sDir = "LAVORATI\" '<<< La subdir in cui saranno spostati i file, con \ finale
'
Set destSh = ThisWorkbook.Sheets(1)
Set fSo = CreateObject("Scripting.FileSystemObject")
myFile = Dir(wDir & "*.xls")
Do
DoEvents
If myFile = "" Then Exit Do
If myFile <> ThisWorkbook.Name Then
Workbooks.Open myFile
Sheets(1).Select
myNext = destSh.Cells(destSh.Rows.Count, "A").End(xlUp).Row + 1
destSh.Cells(myNext, 1) = myFile
destSh.Cells(myNext, 2).Resize(1, 62).Value = Range("A5").Resize(1, 62).Value
ActiveWorkbook.Close False
NName = Format(Now, "yyyy-mm-dd") & "_" & myFile
reDP:
If fSo.FileExists(wDir & sDir & NName) Then
DPlex = True
NName = "#" & NName
End If
If DPlex Then DPlex = False: GoTo reDP
Name wDir & myFile As wDir & sDir & NName
fCnt = fCnt + 1
End If
myFile = Dir
Loop
Set fSo = Nothing
MsgBox ("Completato..." & vbCrLf & "File importati: " & fCnt)
End Sub
Le righe marcate <<< vanno personalizzate come da commento; in particolare in wDir scriverai il percorso completo all'interno del quale posizionerai i file da importare, e in sDir scriverai il nome di una subdirectory (contenuta all'interno di wDir; devi crearla tu) in cui saranno spostati i file dopo l'importazione. Ambedue le stringhe devono avere lo "\" finale.
Salva il file col nome che preferisci.
Quando sei pronto lancia la Sub myImport: ogni file presente nella wDir sara' aperto e il suo contenuto sara' inserito in foglio "1" del nuovo file, a partire da colonna B, accodandoli a quanto gia' presente. In colonna A sara' indicato il file di provenienza di quel record.
Il file importato viene chiuso e spostato nella subdirectory sDir, anteponendo al nome file una stringa nel formato "yyyy-mm-dd", es 2018-09-14; se in wDir un file con quel nome e' gia' presente, sara' ulteriormente anteposto il carattere "#"
Fai sapere...