Here's my feeble attempt:
Sub Import()
Dim blnHasFieldNames As Boolean, blnEXCEL As Boolean, blnReadOnly As Boolean
Dim lngCount As Long
Dim objExcel As Object, objWorkbook As Object
Dim colWorksheets As Collection
Dim strPathFile As String
Dim strPassword As String
Dim strPathTable As String
' Establish an EXCEL application object
On Error Resume Next
Set objExcel = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Set objExcel = CreateObject("Excel.Application")
blnEXCEL = True
End If
Err.Clear
On Error GoTo 0
blnHasFieldNames = False
' Replace C:\Filename.xls with the actual path and filename
strPathFile = "C:\Ryan\"
strPassword = "passwordtext"
blnReadOnly = True ' open EXCEL file in read-only mode
' Open the EXCEL file and read the worksheet names into a collection
strPathFile = Dir(strPathFile & "*.xls")
Do While Len(strPathFile) > 0
strPathFile = strPathFile & strPathFile
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
strPathTable, strPathFile, blnHasFieldNames
strPathFile = Dir()
Loop
'
'Set colWorksheets = New Collection
'Set objWorkbook = objExcel.Workbooks.Open(strPathFile, , blnReadOnly, , _
' strPassword)
'For lngCount = 1 To objWorkbook.Worksheets.Count
' colWorksheets.Add objWorkbook.Worksheets(lngCount).Name
'Next lngCount
' Close the EXCEL file without saving the file, and clean up the EXCEL objects
objWorkbook.Close False
Set objWorkbook = Nothing
If blnEXCEL = True Then objExcel.Quit
Set objExcel = Nothing
' Import the data from each worksheet into a separate table
For lngCount = colWorksheets.Count To 1 Step -1
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
"tbl" & colWorksheets(lngCount), strPathFile, blnHasFieldNames, _
colWorksheets(lngCount) & "$"
Next lngCount
' Delete the collection
Set colWorksheets = Nothing
End Sub
Of course it doesn't work...
It fails on this line:
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
strPathTable, strPathFile, blnHasFieldNames
Message Reads: 'the action or method requires a Table name argument.'
I'm much better with Excel than with Access, but hopefully I'll be up to
speed with this database stuff soon. What am I missing?
Thanks,
Ryan---
[quoted text clipped - 15 lines]