Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Sep 2001
    Location
    Stuck at work..., Missouri, USA
    Posts
    248
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Import all Excel sheets (2003)

    <post#=686362>post 686362</post#> tells me how to reference a specific sheet to import, but I need to import ALL sheets from a workbook, but I do not know their names in advance.

    Is there a way to work around that?

    Thanks!
    <font face="Comic Sans MS">Morgan Erickson</font face=comic>
    morgan.erickson@sprint.com
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18>-From <img src=/S/flags/Colorado.gif border=0 alt=Colorado width=30 height=18> but living in <img src=/S/flags/Missouri.gif border=0 alt=Missouri width=30 height=18>...and working in Kansas.

  2. #2
    3 Star Lounger
    Join Date
    Sep 2001
    Location
    Stuck at work..., Missouri, USA
    Posts
    248
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Import all Excel sheets (2003)

    I love it when I can solve my own questions....

    <pre>Sub ImportAllTabs()
    Dim strPath As String
    strPath = "C:PathToFiles"

    Dim objXL As Object
    Set objXL = CreateObject("Excel.Application")
    Dim strFileName As String
    strFileName = Dir(strPath)
    While strFileName <> ""
    Debug.Print strFileName
    'Open the spreadsheet and get the tab names...
    With objXL
    .Workbooks.Open Filename:=strPath & strFileName

    Dim arrSheetName() As String
    ReDim arrSheetName(objXL.Sheets.Count)

    For x = 1 To objXL.Sheets.Count
    arrSheetName(x) = objXL.Sheets(x).Name
    Next
    End With
    objXL.Workbooks.Close
    'Import the tabs from this spreadsheet
    For x = 1 To UBound(arrSheetName)
    Debug.Print vbTab & arrSheetName(x)
    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "TableToImportTo", _
    strPath & strFileName, True, arrSheetName(x) & "$"
    Next x
    'Next spreadsheet
    strFileName = Dir
    Wend

    objXL.Quit
    Set objXL = Nothing

    End Sub</pre>

    <font face="Comic Sans MS">Morgan Erickson</font face=comic>
    morgan.erickson@sprint.com
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18>-From <img src=/S/flags/Colorado.gif border=0 alt=Colorado width=30 height=18> but living in <img src=/S/flags/Missouri.gif border=0 alt=Missouri width=30 height=18>...and working in Kansas.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Import all Excel sheets (2003)

    Thanks for sharing the solution! <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •