Results 1 to 6 of 6
  1. #1
    kdbailey is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2012
    Posts
    228

    Importing excel tables into access

    I am trying to write some code to import an excel table into access. I want to delete and append a table already in the database. I am having trouble writing the code to do this. If this is at all possible through excel, I would prefer to export the table from excel into access. Otherwise if that's not possible, a macro to import from excel will do.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I've only pulled from Access. If the structure of the spreadsheet will be the same, I'd use the same table. Here's an example:

    CurrentDb.Execute "DELETE * FROM Excel401k"
    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Excel401k", strPath, True

    where strPath contains the path to the Excel file to be imported and Excel401k is the name of the table in Access. The first line empties the table, the second imports the spreadsheet.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I should have added that if you want a new table, the second line will create it if it doesn't exist.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    kdbailey is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2012
    Posts
    228
    Thank you for responding to this post of mine, I have yet to check it. I've been busy with other tasks. I will give this a try as soon as possible.

  5. #5
    kdbailey is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2012
    Posts
    228
    Oh and how would I designate which sheet in excel to pull from?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Along the lines of adding the part in red:

    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Excel401k", strPath, True, "SheetName!"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 10
    Last Post: 12-28-2012, 02:06 PM
  2. Importing Excel Data Tables into Access
    By Itch in forum Programming
    Replies: 5
    Last Post: 09-08-2012, 11:27 AM
  3. Importing from Excel and Junction tables
    By fatalmusic in forum Import/Export Data
    Replies: 0
    Last Post: 04-07-2011, 07:11 AM
  4. Importing Excel datasheets into multiple tables
    By FishMT in forum Import/Export Data
    Replies: 3
    Last Post: 02-08-2011, 07:44 AM
  5. Importing Excel into Access
    By Nel1975 in forum Access
    Replies: 3
    Last Post: 12-30-2009, 10:21 AM

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