0

这是制作新 Excel 工作簿的代码,但每次单击 Access 2007 控制按钮时,我都需要该代码在同一个 Excel 2007 工作簿中创建新工作表。单击控制按钮需要打开 Access 查询并创建 Excel 工作打开Excel 书籍/工作表。Excel 工作簿必须是启用宏的工作簿 .xlsm 格式

' Command104ContrDonatWeekly_Click
'
'------------------------------------------------------------
Private Sub Command104ContrDonatWeekly_Click()
On Error GoTo Command104ContrDonatWeekly_Click_Err

    DoCmd.OpenQuery "Contributors Who Donated in Past Week", acViewNormal, acEdit
    DoCmd.OutputTo acOutputQuery, "Contributors Who Donated in Past Week", "ExcelWorkbook(*.xlsx)", "C:\Users\Michael1\Desktop\KSN\DistributionListWeekly.xlsx", True, "", 0, acExportQualityScreen


Command104ContrDonatWeekly_Click_Exit:
    Exit Sub

Command104ContrDonatWeekly_Click_Err:
    MsgBox Error$
    Resume Command104ContrDonatWeekly_Click_Exit

End Sub
4

1 回答 1

0

您可以使用传输电子表格:

XLFile = "C:\Docs\MyXLFile.xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
    "MyTableOrQuery", XLFile, True, "Sheet2"

FollowHyperlink XLFile

''OR

Shell "Excel.exe " & xlfile, vbNormalFocus
于 2012-04-14T08:31:55.930 回答