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---