我正在将.txt文件直接转换为excel VBA中的数组。 默认分隔符是","(逗号(,我需要将其更改为"vblf"。 我很难弄清楚如何使用我今天的代码来做到这一点。
请帮忙
Const strFileName As String = [file]
Dim CONFIGTXT(1 To 13000) As String
Dim intFileNum As Integer
Dim intCount As Integer
Dim strRecordData As String
intFileNum = FreeFile
intCount = 1
Open strFileName For Input As #intFileNum
Do Until EOF(intFileNum) Or intCount > 13000
Input #intFileNum, strRecordData
CONFIGTXT(intCount) = strRecordData
intCount = intCount + 1
Loop
Close #intFileNum
Range("Q2:Q" & UBound(CONFIGTXT) + 1) = WorksheetFunction.Transpose(CONFIGTXT)
更改
Input #intFileNum, strRecordData
自
Line Input #intFileNum, strRecordData
Input
旨在读取逗号分隔的数据,一次读取一个变量。 例如,如果您有
12345,789
并使用了该语句
Input #intFileNum var1, var2
然后var1
将被赋予值12345
,var2
将被赋予值789
。
Line Input
旨在一次读取一行,由换行符(通常为 CR/LF(分隔。
注意:如果您的数据具有由换行符分隔的信息,则不会将这些部分分隔到数组中的单独条目中。 因此,如果您的数据包含
xxx/xxx/xxx
如果/
实际上是换行符,则整个记录将放置在最终输出中的一个单元格中。