我研究了同样的问题。 Gord 发布的解决方案给了我一个 XML 解释错误。 Cosmichighway 发布了这个解决方案:http://www.utteraccess.com/forum/index.php?showtopic=1981212。
此解决方案适用于 Access 2010 和 Access 2013,也应该适用于 Access 2007。
With CurrentProject.ImportExportSpecifications("nameOfSpecification")
debug.print .XML
.XML = Replace(.XML, varSavedPathName, varNewPathName)
debug.print .XML
End With
我为每次导出生成了一个唯一的文件名,因此在该过程完成后我恢复到原始文件名路径。 WorkHoursTransactions 是一个常量。示例:
CONST ConstExportSavedPathName="c:\temp\Name Of File To Use.xls"
tmpFileName = WorkHoursTransactions & ";" & Format(Now(), "YYYYMMDD-HHMMSS") & ".xls"
With CurrentProject.ImportExportSpecifications(WorkHoursTransactions)
.XML = Replace(.XML, ConstExportSavedPathName, tmpFileName)
'Debug.Print .XML
End With
DoCmd.OpenReport WorkHoursTransactions, acViewReport, , , acWindowNormal
DoCmd.RunSavedImportExport WorkHoursTransactions
' return to original filename
With CurrentProject.ImportExportSpecifications(WorkHoursTransactions)
.XML = Replace(.XML, tmpFileName, ConstExportSavedPathName)
'Debug.Print .XML
End With
我还发现了一个使用即时窗口显示 XML 的好技巧。如果您有一个名为“Export-Table1”的导出规范,则可以将其粘贴到即时窗口中以查看 XML:
? CurrentProject.ImportExportSpecifications.Item("Export-Table1").XML