Results 1 to 4 of 4
  1. #1
    Shahrukh Ali is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2016
    Location
    Pakistan
    Posts
    1

    Excel to Access

    Hello,




    I have got 1400+ Excel workbooks with different columns and a lot of rows. I want to combine them all into one. I think Access Append Query is gonna work fine for me as I am not familiar with coding and vba. But the problem is, even if I go for the append query option it's gonna take days or maybe weeks. Is there any way to bring all excel workbooks in access at once? and combine them all in one query?


    Well, this is just my thought. If anyone has any better way to get it done, please suggest.


    Cheers!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    put all the files into 1 folder, then make a form to run this code.
    click a run button to begin this code, the code suppies the folder where all the worbooks are..

    Code:
    sub btnRun_click()
    ImportAllFilesInDir( "c:\folder\")
    end sub
    
    Public Sub ImportAllFilesInDir(ByVal pvDir)
    Dim vFil, vTargT
    Dim i As Integer
    dim sSql As String
    Dim db 'As Database
    Dim fso
    Dim oFolder, oFile
    
    On Error GoTo errImp
    If Right(pvDir, 1) <> "\" Then pvDir = pvDir & "\"
    
    sTbl = "xlFile"
    Set db = CurrentDb
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set oFolder = fso.GetFolder(pvDir)
    
    For Each oFile In oFolder.Files
    
        vFil = pvDir & oFile.Name
        If InStr(sfile, ".xls") > 0 Then      'ONLY DO EXCEL FILES  
    
           DoCmd.TransferSpreadsheet acImport, sTBL, vFil , True
        endif   
    Next
    
    Set db = Nothing
    Set fso = Nothing
    Set oFile = Nothing
    Set oFolder = Nothing
    DoCmd.SetWarnings True
    Exit Sub
    
    errImp:
    MsgBox Err.Description, vbCritical, "ImportAllFilesInDir():" & Err
    End Sub

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Do all the Excel workbooks have the same column structure, in terms of the number of columns and their names?

    Note: The Transferspreadsheet command should be: DoCmd.TransferSpreadsheet acImport, , sTBL, vFil , True
    (extra comma for a blank second parameter)

    If not, then ranman256's code won't work, at least not properly. If your column names are not the same in all spreadsheets, then the fifth parameter for HasFieldNames = True will cause all sorts of problems.

    Can you describe the spreadsheet format a bit more, please?

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Are there more than 1 worksheet in each workbook??

    You might check out Ken Snell's site:
    Ken's ACCESS Examples and Information for Working With EXCEL Workbook Files
    http://www.accessmvp.com/KDSnell/EXCEL_MainPage.htm

    There is a lot of code for Importing/Exporting Excel to Access

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 04-07-2016, 04:36 AM
  2. Replies: 2
    Last Post: 08-10-2015, 11:53 AM
  3. Import access query data into excel file, using excel vba
    By exceljockey in forum Import/Export Data
    Replies: 3
    Last Post: 11-15-2013, 02:36 PM
  4. Replies: 7
    Last Post: 04-25-2013, 03:47 PM
  5. Replies: 4
    Last Post: 12-17-2012, 01:21 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums