Import multiple Excel tabs into access

J

JP

Is there a way to import multiple excel workbook tabs (with the same
structure) into one access database table without doing the import by tab or
by linking tables to tabs and performing a union query.?
 
G

Graham Mandeno

Hi JP

I'm not sure what you mean by "without doing the import by tab". It seems
to me that is exactly what you need to do.

You can link a given worksheet (tab) in an Excel workbook like this:

DoCmd.TransferSpreadsheet _
acLink, acSpreadsheetTypeExcel9, "TempExcel", _
sFileName, True, sWorksheet & "$"

Here, sFileName is the full path to the Excel file and sWorksheet is the
name of the worksheet. Note that it is necessary to append a dollar sign.

I would put this code in a loop, executing once for each worksheet, and
follow up each TransferSpreadsheet with an append query to add records from
the TempExcel table to your destination table, then delete TempExcel and
repeat.

If the names of the worksheets are pre-known then you can either put them in
an array in your code or read them from a table. If you simply want to
import every worksheet in the workbook, then you can use automation to open
the workbook first and read the names of all the worksheets. Post back if
you need any help with this.
 
K

Ken Snell MVP

Thanks, Gina, for suggesting my web site. Specifically, probably one of
these examples:

Import Data from Specific Worksheets in All EXCEL Files in a single Folder
via TransferSpreadsheet
http://www.accessmvp.com/KDSnell/EXCEL_ImpExp.htm#ImpFldWrkFiles


Import Data from All Worksheets in a single EXCEL File into One Table via
TransferSpreadsheet
http://www.accessmvp.com/KDSnell/EXCEL_ImpExp.htm#ImpAllWkshts


Import Data from All Worksheets in a single EXCEL File into Separate Tables
via TransferSpreadsheet
http://www.accessmvp.com/KDSnell/EXCEL_ImpExp.htm#ImpAllWktsSepTbl
 
G

Gina Whipp

Ken,

You're most welcome! I actually came upon while trying to translate John
Nurick's code (which I still can't get to work) but that's okay because it
helped me find your site! I belive in that... a door closes another door
opens thing :)

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top