我有一个宏设置,点击一个按钮,它将数据导出到一个excel文件,它运行顺利,直到我得到错误的结束RUN TIME ERROR 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
我无法弄清楚错误是什么,它在过去一直有效。直到现在。
答案 0 :(得分:1)
acSpreadsheetTypeExcel7
适用于Excel 95格式,但您要创建.xlsx文件。所以我认为你应该指定一个不同的电子表格类型。试试acSpreadsheetTypeExcel12Xml
。
还可以在C:\以外的位置创建工作簿文件。选择用户具有文件创建权限的文件夹。 C:\ Temp \应该可以工作。
答案 1 :(得分:0)
要使用自动化打开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