vba TransferText 导出到 CSV 不起作用,但 TransferSpreadsheet 到 XLSX 工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26991172/
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
TransferText export to CSV not working, but TransferSpreadsheet to XLSX working
提问by iraserd
I created a Form in which I created a button and through the context menu I activated the Code-generator for VBA. On a click on the button, the query is correctly exported as .xlsx:
我创建了一个表单,在其中创建了一个按钮,并通过上下文菜单激活了 VBA 的代码生成器。单击该按钮,查询将正确导出为 .xlsx:
Option Compare Database
Private Sub Befehl0_Click()
DoCmd.TransferSpreadsheet acExport, , "queryname", "C:\test\queryname.xlsx", -1
End Sub
However, when I modify the export (according to this FAQ):
但是,当我修改导出时(根据此FAQ):
Option Compare Database
Private Sub Befehl0_Click()
DoCmd.TransferText acExportDelim, , "queryname", "C:\test\queryname.csv", -1
End Sub
Nothing happens.
没发生什么事。
I've also tried setting an Export Specification, but that doesn't help either.
我也尝试过设置导出规范,但这也无济于事。
What is wrong here?
这里有什么问题?
回答by iraserd
The answer to this was that there was an error '3441' "Text file specification field separator matches decimal separator or text delimiter", which was only visible when trying to run it in the Direct-window (Ctrl+G).
对此的答案是存在错误“3441”“文本文件规范字段分隔符匹配十进制分隔符或文本分隔符”,该错误仅在尝试在直接窗口 (Ctrl+G) 中运行时可见。
Apparently, when you use a non-English OS this is a problem with the default setting for the delimiters.
显然,当您使用非英语操作系统时,分隔符的默认设置存在问题。
To solve it, an Export Specification has to be provided. However, there are two ways to create such, one of which is wrong.
要解决它,必须提供导出规范。但是,有两种方法可以创建这样的方法,其中一种是错误的。
The same is true for importing, for which I found this on the web:
"Yes i had created the Specification and it is viewable via the Import Wizard, however there is no line for it in MSysIMEXSpecs." Then it seems that you may not have created a true import Specification.
In Access 2007 and newer you can also save the "Import Steps". This is notthe same thing as in Import Specification.
A "Saved Import", will not show up in MSysIMEXSpecs, but a true Import specification should.
To be sure, ...duringthe import process steps, if you click the "Advanced" button to actually create the Import Specification.
The last step of the import process is the "Save Import Steps" dialog box, ...again, this is notthe same thing as an Import Spec. A "Saved Import/export" will be available under: External Data-->Export-->Saved Export ...so check here as well
“是的,我已经创建了规范并且可以通过导入向导查看它,但是 MSysIMEXSpecs 中没有它的行。” 那么看来您可能还没有创建一个真正的导入规范。
在 Access 2007 和更新版本中,您还可以保存“导入步骤”。这 是不是同样的事情,在导入规范。
“保存的导入”不会出现在 MSysIMEXSpecs 中,但真正的导入规范应该。
可以肯定的是,...在导入过程步骤中,如果您单击“高级”按钮来实际创建导入规范。
导入过程的最后一步是“保存导入步骤”对话框,再......,这是不一样的东西作为导入规格。“已保存的导入/导出”将在以下位置提供:外部数据--> 导出--> 已保存的导出...所以也请在此处查看
Using this knowledge, it works by adding the Export Specification "exportcsv" created in the above process.
使用这些知识,它通过添加在上述过程中创建的导出规范“exportcsv”来工作。
DoCmd.TransferText acExportDelim, "exportcsv", "queryname", "C:\test\queryname.csv", -1