G
Guest
Dear All,
Please how can I copy 10 worksheets from a work book in excel to one access
table. The worksheets have identical columns.
I have used Transferspreadsheet method in DoCmd, but it only copies the
first worksheet. It does not loop from 1 to 10. Please see the code below:
Sub xlsSheetLoop()
Dim xlApp As Excel.Application
Dim xlWS As Excel.Worksheet
Dim i As Integer
Dim strFileName As String
Dim wkShName As String
strFileName = "C:\Documents and Settings\a99858\My Documents\P2001.xls"
Set xlApp = New Excel.Application
On Error Resume Next
For i = 0 To xlApp.Worksheets.count
Set xlWS = xlApp.ActiveWorkbook.Worksheets(i)
sheetName = xlWS.Name
DoCmd.TransferSpreadsheet acImport, , "MultiSheet_Example", strFileName, -1,
wkShName & "!A1:E8"
Next i
End Sub
Please how can I copy 10 worksheets from a work book in excel to one access
table. The worksheets have identical columns.
I have used Transferspreadsheet method in DoCmd, but it only copies the
first worksheet. It does not loop from 1 to 10. Please see the code below:
Sub xlsSheetLoop()
Dim xlApp As Excel.Application
Dim xlWS As Excel.Worksheet
Dim i As Integer
Dim strFileName As String
Dim wkShName As String
strFileName = "C:\Documents and Settings\a99858\My Documents\P2001.xls"
Set xlApp = New Excel.Application
On Error Resume Next
For i = 0 To xlApp.Worksheets.count
Set xlWS = xlApp.ActiveWorkbook.Worksheets(i)
sheetName = xlWS.Name
DoCmd.TransferSpreadsheet acImport, , "MultiSheet_Example", strFileName, -1,
wkShName & "!A1:E8"
Next i
End Sub