Natürlich können Sie die Arbeitsmappen in einem Ordner einfach in einer Schleife öffnen und dann eine Schleife über ihre Blätter ziehen. Je nach den geringfügigen Unterschieden im Format müssen Sie beim Importieren möglicherweise etwas mehr Arbeit leisten.
Sub ImportWorkbooks(destination as workbook, importFolderPath As String)
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object associated with the directory
Set objFolder = objFSO.GetFolder(importFolderPath)
'Loop through the Files collection and import each workbook
For Each objFile In objFolder.Files
Dim source As Workbook
Set source = Application.Workbooks.Open(objFile.Path, ReadOnly:=True)
ImportWorkbook source, destination
wb.Close
Set wb = Nothing
Next
Set objFolder = Nothing
Set objFile = Nothing
Set objFSO = Nothing
End Sub
Sub ImportWorkbook(source As Workbook, destination as Workbook)
Dim sheet As Worksheet
'Import each worksheet
For Each sheet In source.Sheets
ImportWorksheet sheet, destination
Next sheet
End Sub
Sub ImportWorksheet(sheet As Worksheet, destination as Workbook)
'Perform your import logic for each sheet here (i.e. Copy from sheet and paste into a
'sheet into the provided workbook)
End Sub
Die grundlegende Verwendung wäre etwa die folgende, um in die aktuelle Arbeitsmappe zu importieren:
ImportWorkbooks ThisWorkbook, "c:\path\to\folder\containing\workbooks\to\import"