Hi,
The following code should get you started
To get the files use something like the following:
Dim foundFnames As New Collection ' collection to store found
filenames
' dirPath & fileFilters are string variables containing
' the path to search
' filefilter should be self explanatory
With Application.FileSearch
.NewSearch
.LookIn = dirPath
.SearchSubFolders = True
.fileName = fileFilter
.MatchTextExactly = True
End With
' apply the search
' vader possibly store the filenames in a collection
With Application.FileSearch
If .Execute(SortBy:=msoSortbyFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
foundFnames.Add .FoundFiles(i)' store the filenames in
a collection
Next i
Else
MsgBox "There were no files found."
End If
End With
' now process each filename found
' need to open the individual spreadsheets listed above
' sheetRange defines name/range of sheet to import
For Each wbFname In foundFnames
DoCmd.TransferSpreadsheet acImport, 8, importTable, wbFname,
hasFldNamesFlg, sheetRange
next wbFname
' there are various error conditions to handle.
' the transfer spreadsheet is ok (see transferspreadsheet action help
topic) but it does have the odd gotcha.
If you are loading the data into an Access table (as opposed to a
linked table) then you should be ok.
Remember that if you get any errors with individual fields the import
is likely to load the rest of the row and just let you know that there
has been a problem in a seperate ImportErrors table.
If you get data conversion errors then use the tool here to make sure
all your cells are of the same datatype.
http://www.j-walk.com/ss/excel/tips/tip28.htm
Good luck,
Mark