We have about 400 Excel files, all single-worksheet files, all formatted exactly the same in one folder.
What’s the easiest way to pull the data from all 400 files into one Access table.
![]() |
Patch reliability is unclear, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Import multiple xls files into 1 table (2003)
In post 659,661, you mentioned that the extension of the files is .dbf. This means that they are DBase files, not Excel spreadsheets.
Start by importing one (any) of the .dbf files into Access using File | Get External Data | Import…
Rename it; in the following code I have assumed that you named it tblImport.
Open the imported table, and delete all records, then close it again.
Press Alt+F11 to activate the Visual Basic Editor.
Select Insert | Module.
Copy the following code (a variant of the code from the Excel thread) into the module.
Sub MergeFiles()
' Path - modify as needed but keep trailing backslash
Const strPath = "C:Excel"
' Arbitrary name for temporary table
Const strTemp = "tblTTTT"
' Name of target table - modify as needed.
Const strTarget = "tblImport"
Dim strFile As String
Dim strSQL As String
On Error GoTo ErrHandler
strSQL = "INSERT INTO [" & tblImport & "] SELECT * FROM " & strTemp
strFile = Dir(strPath & "*.dbf")
Do While Not strFile = ""
' Import into temporary table
DoCmd.TransferDatabase acImport, "dBase 5.0", strPath, acTable, strFile, strTemp
' Transfer records
CurrentDb.Execute strSQL
' Delete temporary table
DoCmd.DeleteObject acTable, "tblTTTT"
strFile = Dir
Loop
ExitHandler:
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation
Resume ExitHandler
End Sub
Modify the path (keeping the backslash at the end!) and the name of the imported table.
Click anywhere in the code, and press F5 to run it.
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications