现有Access 2007宏的代码修改 - 旨在创建&打开(从Access)现有Excel 2007工作簿中的新Excel工作表?

时间:2012-04-14 06:39:57

标签: ms-access excel-2007 ms-access-2007 access-vba

以下是使新Excel工作预订的代码,但每次点击时,我都需要代码在同一个Excel 2007工作簿中创建新作品 SHEET Access 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

1 个答案:

答案 0 :(得分:0)

您可以使用Transferspreadsheet:

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

FollowHyperlink XLFile

''OR

Shell "Excel.exe " & xlfile, vbNormalFocus