Dim lngColumn As Long
Dim xlx As Object, xlw As Object, xls As Object, xlc As Object
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim blnEXCEL As Boolean [LEFT][SIZE=2]blnEXCEL = False
[COLOR=#008000]' Establish an EXCEL application object[/COLOR]
On Error Resume Next
Set xlx = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Set xlx = CreateObject("Excel.Application")
blnEXCEL = True
End If
Err.Clear
On Error GoTo 0
[COLOR=#008000]' Change [I]True[/I] to [I]False[/I] if you do not want the workbook to be
' visible when the code is running[/COLOR]
xlx.Visible = True
[COLOR=#008000]' Replace [I]C:\Filename.xls[/I] with the actual path and filename
' of the EXCEL file from which you will read the data[/COLOR]
Set xlw = xlx.Workbooks.Open("C:\Filename.xls", , True) [COLOR=#008000]' opens in read-only mode[/COLOR]
[COLOR=#008000]' Replace [I]WorksheetName[/I] with the actual name of the worksheet
' in the EXCEL file[/COLOR]
Set xls = xlw.Worksheets("WorksheetName")
[COLOR=#008000]' Replace [I]A1[/I] with the cell reference from which the first data value
' (non-header information) is to be read[/COLOR]
Set xlc = xls.Range("A1") [COLOR=#008000]' this is the first cell that contains data[/COLOR]
Set dbs = CurrentDb()
[COLOR=#008000]' Replace [I]QueryOrTableName[/I] with the real name of the table or query
' that is to receive the data from the worksheet[/COLOR]
Set rst = dbs.OpenRecordset("QueryOrTableName", dbOpenDynaset, dbAppendOnly)
[COLOR=#008000]' write data to the recordset[/COLOR]
Do While xlc.Value <> ""
rst.AddNew
For lngColumn = 0 To rst.Fields.Count - 1
rst.Fields(lngColumn).Value = xlc.Offset(0, lngColumn).Value
Next lngColumn
rst.Update
Set xlc = xlc.Offset(1,0)
Loop
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
[COLOR=#008000]' Close the EXCEL file without saving the file, and clean up the EXCEL objects[/COLOR]
Set xlc = Nothing
Set xls = Nothing
xlw.Close False
Set xlw = Nothing
If blnEXCEL = True Then xlx.Quit
Set xlx = Nothing[/SIZE]