I would still use the TransferSpreadsheet Method.
Some assumptions;
there is an access database named 'test.mdb' located in 'D:\DATA\Access'
there is a workbook named 'SomeWB.xls' located in 'D:\DATA\Excel'
there are some column names in the workbook at A1:A3
there is some data in the workbook at B1:C3
Paste the code below in a new module in 'D:\DATA\Excel\SomeWB.xls' and run
SendData
------------------------------------
Public Sub SendData()
Dim strConPathToDB As String
strConPathToDB = "D:\DATA\Access\test.mdb"
Dim appAccess As Object
Set appAccess = CreateObject _
("Access.Application." & AccessVersion & "")
appAccess.OpenCurrentDatabase strConPathToDB
appAccess.Visible = False
appAccess.DoCmd.TransferSpreadsheet _
acImport, acSpreadsheetTypeExcel9, _
"tblNames", "D:\DATA\Excel\SomeWB.xls", _
True, "a1:c3"
appAccess.CloseCurrentDatabase
appAccess.Quit
End Sub
Public Function AccessVersion()
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
Select Case WshShell.RegRead("HKCR\Access.Application\CurVer\")
Case "Access.Application.8"
AccessVersion = 8
Case "Access.Application.9"
AccessVersion = 9
Case "Access.Application.10"
AccessVersion = 10
Case "Access.Application.11"
AccessVersion = 11
End Select
End Function
------------------------------------
--
Regards,
Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect
:
| Thanks for you response.
|
| The code is actually running in an Excel spreadsheet and I'm opening
another
| spreadsheet and wanting to paste the data into an Access table.