Results 1 to 3 of 3
  1. #1
    Evocube is offline Novice
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    3

    Import Specific Cells from Excel to Access

    I need of a little help on this code. It is suppose to import a specific cell into a specific column of my table. (eventually i want this to go through several excel files, small steps LOL)
    Here is my code (using access 2007 going to 2003 excel files)

    Sub ADD()
    Dim myRec As DAO.Recordset

    Dim xl As Excel.Application
    Dim xlsht As Excel.Worksheet


    Dim xlWrkBk As Excel.Workbook

    Set xl = CreateObject("Excel.Application")
    Set xlWrkBk = GetObject("C:\Documents and Settings\*******\Desktop\*******.xls")
    Set xlsht = xlWrkBk.Worksheets(1)
    Set myRec = CurrentDb.OpenRecordset("Customers", dbOpenDynaset)
    myRec.AddNew
    myRec.Fields("Customer") = xlwrksht.Cells(11, "G")
    'myRec.Fields("Test2") = xlwrksht.Cells(9, "E")
    'myRec.Fields("Test3") = xlwrksht.Cells(11, "E")
    myRec.Update
    End Sub

    I keep getting error 424 object required on this line:
    myRec.Fields("Customer") = xlwrksht.Cells(11, "G")

    Thanks!

  2. #2
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    wrong approach.

    one cell - one field - one time? ...copy & paste!

    but if you need this to be repeating and automated - then import the excel data into a generic new table and use an append query to put the field/record of choice into the table/field of choice....

  3. #3
    mikas is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jan 2012
    Posts
    1
    error here : myRec.Fields("Customer") = xlwrksht.Cells(11, "G")
    xlwrksht - is not defined, you defined xlsht instead

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Import excel sheets to access.
    By calexandru in forum Import/Export Data
    Replies: 0
    Last Post: 08-19-2009, 09:44 AM
  2. Excel exporting in single cells
    By Paolo29011982 in forum Import/Export Data
    Replies: 0
    Last Post: 07-29-2009, 04:48 AM
  3. Replies: 2
    Last Post: 07-15-2009, 04:08 AM
  4. Import Excel Worksheets into Access 2003
    By KramerJ in forum Programming
    Replies: 0
    Last Post: 03-18-2009, 04:11 PM
  5. VBA Opening Excel File and Placing Data in Cells
    By BobTHG in forum Programming
    Replies: 0
    Last Post: 01-13-2008, 03:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums