Multiple excel files

D

dchristo

I have multiple excel files in the same format, just different names that I
need to import into an Access table? How can accomplish this?

All the files are in the same directory.
 
K

Ken Snell \(MVP\)

Same ACCESS table? If yes, this generic code can be modified to work for
you.

Dim strFile As String
Const strPath As String = "PathToTheEXCELFilesFolder\"
Const blnHasFieldNames As Boolean = True ' Or set to False
Const strTablename As String = "NameOfACCESSTable"
strFile = Dir(strPath & "*.xls")
Do While strFile <> ""
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
strTablename, strPath & strFile, blnHasFieldNames
strFile = Dir()
Loop
 
D

dchristo

Thanks for the reply.

I tried this as a public function, I am getting the following error message
at this line:

strFile = Dir(strPath & "*.xls")

Error: Constant Expression Required.
 
D

dchristo

I got it - thanks for all your help.

Ken Snell (MVP) said:
Same ACCESS table? If yes, this generic code can be modified to work for
you.

Dim strFile As String
Const strPath As String = "PathToTheEXCELFilesFolder\"
Const blnHasFieldNames As Boolean = True ' Or set to False
Const strTablename As String = "NameOfACCESSTable"
strFile = Dir(strPath & "*.xls")
Do While strFile <> ""
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
strTablename, strPath & strFile, blnHasFieldNames
strFile = Dir()
Loop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top