How to export all tables from an Access Database into Excel - A sheet for each table

前端 未结 3 850
一向
一向 2021-02-04 09:17

I have an Access database with ~30 tables.

How can I export all 30 tables into separate sheets in an Excel workbook?

I\'m hoping to find some VBA/VBS code which

3条回答
  •  不知归路
    2021-02-04 10:17

    Here is formated and fixed version of above code. We don't need MSys tables in excel file and dbo prefix in sheet names. Export also can be made relative to MS Access db or fixed.

    Here is code:

    Sub exportTables2XLS()
    Dim td As DAO.TableDef, db As DAO.Database
    Dim out_file As String
    
    out_file = CurrentProject.path & "\excel_out.xls" 
    
    Set db = CurrentDb()
       For Each td In db.TableDefs
         If Left(td.Name, 4) = "MSys" Then
         '// do nothing -- skip
       Else
         DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
         td.Name, out_file, True, Replace(td.Name, "dbo_", "")
       End If 
       Next
    End Sub
    

提交回复
热议问题