Combina cartelle di lavoro

Sommario

Per combinare le cartelle di lavoro in Excel utilizzare il codice seguente. Questo codice prenderà tutti i primi fogli in ogni cartella di lavoro trovata in una directory:

123456789101112131415161718192021222324252627282930313233343536 "Unisci cartelle di lavoro"Sub MergeWBs()Application.EnableEvents = FalseApplication.ScreenUpdating = FalseDim path As String, ThisWB As String, lngFilecounter As LongDim wbDest As Workbook, shtDest As Worksheet, ws As WorksheetDim Filename As String, Wkb As WorkbookDim CopyRng As Range, Dest As RangeDim RowofCopySheet As IntegerRowofCopySheet = 2 ' Riga da cui iniziare nei fogli da cui stai copiandoThisWB = ActiveWorkbook.Namepercorso = GetDirectory ("Seleziona una cartella contenente i file Excel che desideri unire")Imposta shtDest = ActiveWorkbook.Sheets(1)Nome file = Dir(percorso & "\*.xlsm", vbNormal)Se Len(Filename) = 0 Then Exit SubEsegui fino al nome del file = vbNullStringIf Not Filename = ThisWB ThenImposta Wkb = Workbooks.Open(Filename:=path & "\" & Filename)Imposta CopyRng = Wkb.Sheets(1).Range(Cells(RowofCopySheet, 1), Cells(ActiveSheet.UsedRange.Rows.Count, ActiveSheet.UsedRange.Columns.Count))Imposta Dest = shtDest.Range("A" & shtDest.UsedRange.SpecialCells(xlCellTypeLastCell).Row + 1)CopiaRng.Copia DestWkb.Chiudi FalsoFinisci seNome file = Dir()Ciclo continuoApplication.EnableEvents = TrueApplication.ScreenUpdating = TrueMsgBox "Macro completata"Fine sottotitolo

Signor Excel

wave wave wave wave wave