I tried to do this a few days ago; never figured it out. How do you "read"
the worksheet names from the Excel files?
I tried this, but it didn't work:
For i = 1 To Workbooks(MyWorkBook).Sheets.Count
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
strTablename, strPath & strFile, blnHasFieldNames
Next i
Here is the code that I was working with (this imported the first sheet in
each Excel file):
Sub ImportAllExcelFiles()
On Error GoTo Err_F
Dim strPathFile As String, strFile As String, strPath As String, strSpec As
String
Dim strTable As String, ynFieldName As Boolean
ynFieldName = False
strPath = "C:\Import\"
'strSpec = "NameOfImportSpecification" ' Put your name here
strTable = "tablename"
strFile = Dir(strPath & "*.xls")
Do While Len(strFile) > 0
strPathFile = strPath & strFile
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, strTable,
strPathFile, ynFieldName
' Uncomment out the next code step if you want to delete the file after it's
imported
' Kill strPathFile
strFile = Dir()
Loop
Exit_F:
Exit Sub
Err_F:
MsgBox Err.Number & " " & Err.Description
Resume Exit_F
End Sub
Again, it reads the first sheet, and only the first sheet, in each Excel file.
How can this be modified to read multiple sheets in each Excel file, and
also loop through all the Excel files in a folder?
Thanks,
Ryan---
--
RyGuy--
If the post was helpful, please click the ''Yes'' button to indicate such!
"Ken Snell MVP" wrote:
> Do you know the names of the worksheets in the files? Or do you have to
> "read" the worksheet names from the EXCEL files?
>
> If the former is true, you can use the code at this web page as a starting
> point. Just add another loop or extra steps for the various worksheets.
> Import Data from All EXCEL Files in a single Folder via TransferSpreadsheet
> http://www.accessmvp.com/KDSnell/EXC...ImpFolderFiles
> --
>
> Ken Snell
> <MS ACCESS MVP>
> http://www.accessmvp.com/KDSnell/
>
>
> "KramerJ" <(E-Mail Removed)> wrote in message
> news:6E58A88E-0A62-42FA-9E32-(E-Mail Removed)...
> > How do I import an EXCEL FILE WITH MULTIPLE WORKSHEETS into Access 2003. I
> > am
> > creating a master table in Access of archived Excel files, each file has
> > multiple worksheets. Is there a need to use both SQL and VBA to
> > accomplished
> > the import. TIA
>
>
>