Import many Excel worksheets into the same Access table

Juan Pablo González

MrExcel MVP
Joined
Feb 8, 2002
Messages
11,959
Hey,

I've got a workbook with 86 sheets, all representing a different date. I need to import this into the same table, but I really don't feel like using the wizard one step at a time.

I've succesfuly used the DoCmd.TransferText command to import many text files, and thought that the DoCmd.TransferSpreadsheet was the one I needed... but, I got stuck because I don't see anyway of telling Access WHICH sheet it should import, it looks like it assumes the first one ?

This is my current code:<pre>Private Sub Comando0_Click()
Dim WB As Workbook
Dim WS As Worksheet
Dim XL As Excel.Application
Dim Rng As Range
Dim i As Long
Dim tblName As String
Dim Count As Long

Set XL = New Excel.Application
Set WB = XL.Workbooks.Open("D:ProyectosPasivosReq Cheque CampanaSolicitudesNoviembreaEnero.xls")
Count = WB.Worksheets.Count
tblName = "Movimientos"
For i = 1 To Count
Set Rng = WB.Worksheets(i).Range("A1").CurrentRegion
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, tblName, WB.FullName, True, Rng.Address
Next i
End Sub</pre>Now, how do I do this?

_________________
Regards,

Juan Pablo G.
MrExcel.com Consulting
This message was edited by Juan Pablo G. on 2003-02-13 18:51
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Ok, solved it. Had to change two things, first, open the workbook as ReadOnly, and second, pass the "external" address of the range, that is, including the sheet name.
 
Upvote 0

Forum statistics

Threads
1,221,499
Messages
6,160,169
Members
451,629
Latest member
MNexcelguy19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top