Question : Import multiple Excel files into Access

I have a bunch of individual Excel files. They are all contained in the same folder. Each one only has a few records. They all have the same format (data in the first 5 columns only). I'm looking for an import program that will import all the files in the folder so that I don't have to manually do a "get external data" for each individual file since there are like a 100 of them and I will be having to do this task frequently in the future.  Or what also would be fine is a macro to combine all of the excel files into one big file. Either way is fine.... a program in Access or a program in Excel. Thanks.

Answer : Import multiple Excel files into Access

Hello dbfromnewjersey,

Assuming you want all Excel files in a given folder...

Dim fso As Object, fld As Object, fil As Object

Set fso = CreateObject("Scripting.FIleSystemObject
Set fld = fso.GetFolder("c:\folder\subfolder")

For Each fil In fld.Files
    If LCase(Right(fil.Name, 4)) = ".xls" Then
        DoCmd.TransferSpreadsheet TransferType:=acImport, _
            TableName:= "NameOfTable", FileName:=fil.Path, _
            HasFieldNames:=True
    End If
Next

Set fil = Nothing
Set fld = Nothing
Set fso = Nothing

Regards,

Patrick
Random Solutions  
 
programming4us programming4us