M
munscher
John Nurick posted the following about 2 months ago
Microsoft MVP Joe Fallon has posted the skeleton code below fo
importing data from all files in a folder. It assumes text files bu
will work for Excel worksheets if you replace the DoCmd.TransferTex
statement with the appropriate DoCmd.TransferSpreadsheet - provided tha
you only need to import one worksheet from each workbook and that al
the worksheets have the same name (e.g. "Sheet1")
If those conditions don't hold (e.g. importing multiple sheets from on
workbook) it's still possible but more difficult.
'CODE START
Private Sub btnImportAllFiles_Click(
'procedure to import all files in a directory and delete them
'assumes they are all the correct format for an ASCII delimited import
Dim strfile As Strin
ChDir ("c:\MyFiles"
strfile = Dir("FileName*.*"
Do While Len(strfile) >
DoCmd.TransferText acImportDelim, "ImportSpecName", "AccessTableName"
"c:\MyFiles\" & strfile, Tru
'delete the file (consider moving it to an Archive folder instead.
Kill "c:\MyFiles\" & strfil
strfile = Di
Loo
End Su
'CODE END
Microsoft MVP Joe Fallon has posted the skeleton code below fo
importing data from all files in a folder. It assumes text files bu
will work for Excel worksheets if you replace the DoCmd.TransferTex
statement with the appropriate DoCmd.TransferSpreadsheet - provided tha
you only need to import one worksheet from each workbook and that al
the worksheets have the same name (e.g. "Sheet1")
If those conditions don't hold (e.g. importing multiple sheets from on
workbook) it's still possible but more difficult.
'CODE START
Private Sub btnImportAllFiles_Click(
'procedure to import all files in a directory and delete them
'assumes they are all the correct format for an ASCII delimited import
Dim strfile As Strin
ChDir ("c:\MyFiles"
strfile = Dir("FileName*.*"
Do While Len(strfile) >
DoCmd.TransferText acImportDelim, "ImportSpecName", "AccessTableName"
"c:\MyFiles\" & strfile, Tru
'delete the file (consider moving it to an Archive folder instead.
Kill "c:\MyFiles\" & strfil
strfile = Di
Loo
End Su
'CODE END