Access table data to Excel

前端 未结 5 1674
傲寒
傲寒 2020-12-18 13:07

I have a problem I have got stuck on.

I want to export my Access table to an Excel file. Currently, I do that using DoCmd.TransferSpreadsheet, but I wa

5条回答
  •  渐次进展
    2020-12-18 13:30

    This Excel macro retrieves data from your MS Access database:

    Sub Makro1()
    ''
    Const sDB = "c:\db1.mdb"
    Const sSQL = "SELECT * FROM Table1"
    
        With ActiveSheet.QueryTables.Add(Connection:= _
            "ODBC;DSN=MS Access-database;DBQ=" + sDB + ";FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;" _
            , Destination:=Range("A1"))
            .CommandText = Array(sSQL)
            .Name = "Query1"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = True
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .PreserveColumnInfo = True
            .Refresh BackgroundQuery:=False
        End With
    End Sub
    

提交回复
热议问题