简体   繁体   English

VBA文本到列FieldInfo

[英]VBA Text to columns FieldInfo

FieldInfo:=Array(Array(0, 5), Array(8, 1))

I am trying to use text to columns fixed width. 我正在尝试使用文本来固定宽度的列。

For this, I have recorded a macro. 为此,我录制了一个宏。

I can understand some of the code since I am new to VBA. 因为我是VBA的新手,所以我可以理解一些代码。

However, The above code is not clear. 但是,上面的代码不清楚。

Can someone explain what this code does? 有人可以解释此代码的作用吗?

FieldInfo: 字段信息:

An array containing parse information for the individual columns of data. 一个数组,其中包含各个数据列的解析信息。 The interpretation depends on the value of DataType. 解释取决于DataType的值。 When the data is delimited, this argument is an array of two-element arrays, with each two-element array specifying the conversion options for a particular column. 在对数据进行定界时,此参数是一个由两个元素组成的数组,每个两个元素组成的数组指定特定列的转换选项。 The first element is the column number (1-based), and the second element is one of the xlColumnDataTypeconstants specifying how the column is parsed. 第一个元素是列号(从1开始),第二个元素是xlColumnDataType常量之一,用于指定如何解析列。

The example: 这个例子:

Array(Array(3, 9), Array(1, 2))

If the source data has fixed-width columns, the first element of each two-element array specifies the starting character position in the column (as an integer; 0 (zero) is the first character). 如果源数据具有固定宽度的列,则每个由两个元素组成的数组的第一个元素将指定列中的起始字符位置(以整数表示;第一个字符为0(零))。 The second element of the two-element array specifies the parse option for the column as a number from 1 through 9, as listed above. 包含两个元素的数组的第二个元素将列的解析选项指定为1到9之间的一个数字,如上所述。

Source: https://msdn.microsoft.com/en-us/vba/excel-vba/articles/range-texttocolumns-method-excel 来源: https : //msdn.microsoft.com/en-us/vba/excel-vba/articles/range-texttocolumns-method-excel

using the source from @Vityata's answer , it means that you made two columns with the two arrays inside the outer array representing the two resulting columns: 使用@Vityata的答案中 ,这意味着您创建了两列,而外部数组中的两个数组代表了两个结果列:

Array(0, 5) the 1st column starts at character # 0 (the first char) and the type is YMD date (type 5 ) Array(0, 5)第一列从字符# 0 (第一个字符)开始,类型为YMD date (类型5

Array(8, 1) the 2nd column starts at character # 8 (the ninth char = the first column is 8 char wide) The second column's type is General (type 1 ) Array(8, 1)第二列从字符# 8开始(第九个字符=第一列为8个字符宽)第二列的类型为General (类型1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM