在表单中,我创建了一个按钮(导出到excel)。
代码vba:
Private Sub Commande97_Click()
Dim db As DAO.Database
Dim req As DAO.QueryDef
Set db = CuurentDb
Set req = db.QueryDefs("R_BC_infos")
req.SQL = SQLListBC
Set req = Nothing
Set db = Nothing
DoCmd.OutputTo acOutputQuery, "R_BC_infos", "ExcelWorkbook(*.xlsx)", "", True, "", acExportQualityPrint
End Sub
然而,当我点击按钮时,它会给我错误对象请求。
答案 0 :(得分:0)
我更改了代码,我使用了DoCmd.TransferSpreadsheet方法并且可以正常工作
Private Sub Commande97_Click() DoCmd.TransferSpreadsheet acExport,acSpreadsheetTypeExcel12,“R_BC_infos”,“C:\ Users \ reunion \ Desktop \ html \ Classeur.xls”'文件路径 结束子