Import Excel Files from Subfolders into a Microsoft Access Table
Question details
Combine Excel files from multiple subfolders into one Access table, using row 5 as the header row.

- Product
- Microsoft Access and Microsoft Excel
- Device & OS
- not provided
- Scenario
- The workbooks share a layout and are stored throughout a directory tree.
- Observed behavior
- The user needs each workbook imported into a single table without treating the first four worksheet rows as data or headers.
Confirm the root folder, worksheet name, and first and last data columns shared by the workbooks. Make sure row 5 contains matching field names and that corresponding columns use compatible data types.
Use Access VBA to import Excel files recursively
Scan a root folder and its subfolders, then import each .xls or .xlsx file from row 5 into one Access table.
The example imports columns A through D from a worksheet named Sheet1. Change the folder path, sheet name, and column range to match your files. Access creates CombinedData from the first import if the table does not already exist; later imports append to it.
Open the destination database in Access, press Alt+F11, and select Insert > Module.
Paste this code into the module: Public Sub ImportExcelTree() Dim fso As Object Set fso = CreateObject("Scripting.FileSystemObject") ImportFolder fso.GetFolder("C:\ExcelData"), fso End Sub Private Sub ImportFolder(ByVal folder As Object, ByVal fso As Object) Dim file As Object, child As Object Dim ext As String, sheetRange As String Dim spreadsheetType As Long For Each file In folder.Files ext = LCase(fso.GetExtensionName(file.Name)) If Left(file.Name, 2) <> "~$" Then If ext = "xls" Or ext = "xlsx" Then If ext = "xls" Then spreadsheetType = acSpreadsheetTypeExcel8 sheetRange = "Sheet1$A5:D65536" Else spreadsheetType = acSpreadsheetTypeExcel12Xml sheetRange = "Sheet1$A5:D1048576" End If DoCmd.TransferSpreadsheet acImport, spreadsheetType, _ "CombinedData", file.Path, True, sheetRange End If End If Next file For Each child In folder.SubFolders ImportFolder child, fso Next child End Sub
Replace C:\ExcelData with the root folder. In both sheetRange assignments, replace Sheet1 and A:D with the common worksheet name and exact columns to import. Keep row 5 as the first row so Access uses it for field names.
Place the cursor inside ImportExcelTree and press F5. In the Access navigation pane, open CombinedData and check the imported records and field types. Review any import-error tables created by Access.

Review Excel source files with WPS Office
WPS Office is a free, lightweight, easy-to-use Office alternative with a familiar interface. Open and review Excel workbooks before an Access import, and move between common Office formats with minimal disruption. The Access database import itself must still be performed in Access.

Frequently Asked Questions
How does Access use row 5 as the header row?
The TransferSpreadsheet range starts at A5, and its HasFieldNames argument is set to True. Access treats the first row of that range as field names.
Can I import a different worksheet or more columns?
Yes. Edit both sheetRange values in the VBA module. Replace Sheet1 with the worksheet name and A:D with the exact columns containing your headers and data.
Will the routine find files in nested subfolders?
Yes. ImportFolder calls itself for each subfolder under the root path. The example processes .xls and .xlsx files and skips temporary files whose names start with ~$.
Why did some values produce import errors?
A source value may not fit the destination field's data type, or a field name may not match. Open any import-error tables in the Access navigation pane and compare the affected workbook columns with CombinedData.




