Link to home
Start Free TrialLog in
Avatar of AndyC1000
AndyC1000

asked on

How to automatically import sheets from excel into access database

Dear all,

I've been manually importing data from an excel workbook into an access database using External data -> Import.  There are over 20 sheets of data is there a way to automatically set up an import procedure that will iterate through the sheets using all the import wizard default options?

Thanks
Avatar of AndyC1000
AndyC1000

ASKER

Hello,

I've tried the example from the first link.  I'm having troubles with the table name argument I would like this to be the same as the excel sheet name.  The current error "action or method requires a table name argument".

Sub ImportAllSheets()
Dim objXL As Object
Dim sTable, xlPath As String, i As Integer

xlPath = "C:\Export\TestBook1.xlsx"

Set objXL = CreateObject("Excel.Application")
    objXL.Workbooks.Open xlPath, , True
    With objXL
        For i = 1 To .Worksheets.Count
            DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, sheet1, xlPath, True
        Next
    End With
    objXL.Quit
    Set objXL = Nothing

End Sub

Open in new window


Thanks
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial