vba Workbooks.OpenText 不采用“fieldinfo”参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9559579/
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
Workbooks.OpenText doesn't take 'fieldinfo' parameter
提问by nixda
The following code demonstrates the problem which is stated in questions title.
以下代码演示了问题标题中所述的问题。
Copy & paste it in a new Microsoft Excel 2003 workbook.
将其复制并粘贴到新的 Microsoft Excel 2003 工作簿中。
Sub mytest()
mypath = Application.GetSaveAsFilename()
Workbooks.OpenText Filename:=mypath, DataType:=xlDelimited, _
TextQualifier:=xlTextQualifierDoubleQuote, _
semicolon:=True, _
fieldinfo:=Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2)), _
Local:=True
End Sub
Execute the code. It will ask for an input file where you should use this semicolon-seperated test.csv. It creates a new workbook and imports all the data from test.csv to sheet1.
执行代码。它将要求输入文件,您应该在其中使用此分号分隔的test.csv。它创建一个新工作簿并将所有数据从 test.csv 导入到 sheet1。
The picture below shows the result
下图显示了结果
But It should have shown a result like this
但它应该显示这样的结果
fieldinfo:=Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2))
states that Excel should treat all imported data as text. Unfortunately it doesn't.
fieldinfo:=Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2))
指出 Excel 应将所有导入的数据视为文本。不幸的是它没有。
- The two-dimensional array: first number is the column number, second number stands for data typewhere 2 stands for text
- I have to use the 'local'-parameter because I'm on a localized OS with a localized Office 2003
- The operating system is irrelevant since it happens on Windows XP and on Windows 7
- 二维数组:第一个数字是列号,第二个数字代表数据类型,其中2代表文本
- 我必须使用“本地”参数,因为我在本地化的操作系统上使用本地化的 Office 2003
- 操作系统无关紧要,因为它发生在 Windows XP 和 Windows 7 上
Can someone show me how to use opentext and fieldinfo in the correct way?
有人可以告诉我如何以正确的方式使用 opentext 和 fieldinfo 吗?
I already know the work-around with QueryTables.Add(Connection[...].
But thats not a solution for my case.
我已经知道 QueryTables.Add(Connection[...]
的解决方法。但这不是我的情况的解决方案。
采纳答案by nixda
If you rename the extension from the input file from .csv to .txt the fieldinfo
parameter works as designed.
如果您将输入文件中的扩展名从 .csv 重命名为 .txt,则fieldinfo
参数按设计工作。