使用 vba 将 MS Access 查询输出到 Excel

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18280067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:26:24  来源:igfitidea点击:

Output MS Access Query to Excel with vba

vbams-accessms-access-2007access-vba

提问by RestitutorOrbis

Working with MS Access 2007, I have a query I'd like to run and export the results to a specific workbook in a saved Excel workbook. I have the following code written using DoCmd. First I open the query (this works) and then I try to output the results to excel.

使用 MS Access 2007,我有一个查询,我想运行并将结果导出到保存的 Excel 工作簿中的特定工作簿。我使用 DoCmd 编写了以下代码。首先我打开查询(这有效),然后我尝试将结果输出到 excel。

DoCmd.OpenQuery "MyQueryName", acViewNormal, acEdit

DoCmd.OutputTo acOutputQuery, "Aging By Desk - Onboarding Team", acFormatXLS, _
    "filepath.SuperTest.xls", "SuperTest.xls", True

However, when this code is run, I get the following error message: "An Expression you entered is the wrong data type for one of the arguments". I've been playing around with each argument, but can't seem to locate the problem. Any ideas? Am I on the right path?

但是,当运行此代码时,我收到以下错误消息:“您输入的表达式是其中一个参数的错误数据类型”。我一直在讨论每个论点,但似乎无法找到问题所在。有任何想法吗?我在正确的道路上吗?

采纳答案by Johnny Bones

You've got too many arguments. From Microsoft'swebsite:

你的论据太多了。从微软的网站:

expression.OutputTo(ObjectType, ObjectName, OutputFormat, OutputFile, AutoStart, TemplateFile, Encoding)

expression.OutputTo(ObjectType, ObjectName, OutputFormat, OutputFile, AutoStart, TemplateFile, Encoding)

Take out one of those Excel filenames you have and it should work.

取出您拥有的那些 Excel 文件名之一,它应该可以工作。