导出macros错误

我有一个macros设置在哪里点击一个button,它将数据导出到Excel文件,它运行顺利,似乎直到我得到错误的结束运行时错误3434不能扩展名称范围

代码是:

Public Sub ExportTblToExcel() Const FILE_PATH As String = "C:\" Dim FULLPath As String strFullPath = FILE_PATH DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, "tblExport", strFullPath & "CD_Data.xlsx", False MsgBox ("Export Complete. Check the C:\ Drive for the Document CD_Data") End Sub 

突出显示的部分是:

 DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, "tblExport", strFullPath & "CD_Data.xlsx", False 

我不知道错误是什么,过去一直工作到现在为止。

acSpreadsheetTypeExcel7适用于Excel 95格式,但您希望创build一个.xlsx文件。 所以我认为你应该指定一个不同的电子表格types。 试试acSpreadsheetTypeExcel12Xml

另外创build您的工作簿文件以外的地方C:\。 select用户具有文件创build权限的文件夹。 C:\ Temp \应该工作。

要使用自动化来打开excel文件,请使用类似…例程的底部

 Private Sub cmdExport_Click() Dim myFile As String Dim myDate As String Dim xlApp As Object myDate = Day(txtEnd) & "-" & Month(txtEnd) & "-" & Year(txtEnd) myFile = WorkingDbFolder & "DKRForAccounts_" & myDate & ".xls" 'create temp table with combined data DoCmd.SetWarnings False DoCmd.OpenQuery "qryrptAccounts_XXX" DoCmd.OpenQuery "qryrptAccounts_XXXDepRuns" DoCmd.SetWarnings True MsgBox "Excel about to open ... This only summaries Customers with an Email Address" DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "tblTEMP_XXXaccounts", myFile, True Set xlApp = CreateObject("Excel.Application") xlApp.Visible = True xlApp.Workbooks.Open myFile, True, False Set xlApp = Nothing End Sub