Cloudy,
Use automation to do this. If each worksheet is going into a separate
table, and the table name and worksheet name are not the same, I would
create a table to store the worksheet name and the destination table name.
If you use such a table, you can remove all of the code in this module
except the last loop, and instead of looping through the array, you would
open a recordset based on the afore mentioned table, and loop through the
various records. If, on the other hand, you just want to import all of the
worksheets in the workbook into tables with the same name as the worksheet,
it might look somthing like the following.This subroutine uses late binding
so it doesn't matter which version of Excel you have.
Public Sub ImportFromExcel(Filename As String)
Dim oXL As Object ' Excel.Application
Dim oWbk As Object ' Excel.Workbook
Dim oSht As Object 'Excel.Worksheet
Dim intSht As Integer
Dim xlOpen As Boolean
Dim wkshtArray() As String
Dim strTableName As String, strRange As String
'Set inline error handling for this initial step
On Error Resume Next
'Use GetObject to select the open instance of Excel, if one is open
'If open, then set the variable xlOpen to true, so as not to close it on
the way out
'If XL is not already open, then open it and set xlOpen to False
Set oXL = GetObject(, "Excel.Application")
If Err.Number = 0 Then
xlOpen = True
Else
xlOpen = False
Set oXL = CreateObject("Excel.Application")
End If
'Make Excel visible
oXL.Visible = True
'Open the workbook
Set oWbk = oXL.Workbooks.Open(Filename)
ReDim wkshtArray(oWbk.Sheets.Count - 1)
intSht = 0
For Each oSht In oWbk.Sheets
wkshtArray(intSht) = oSht.Name
intSht = intSht + 1
Next
oWbk.Close
Set oWbk = Nothing
oXL.Quit
Set oXL = Nothing
For intSht = LBound(wkshtArray) To UBound(wkshtArray)
Debug.Print wkshtArray(intSht)
strTableName = wkshtArray(intSht)
strRange = wkshtArray(intSht) & "!"
DoCmd.TransferSpreadsheet acImport, , strTableName, Filename, True,
strRange
Next
End Sub