我需要将信息从文本文件保存到数组中。但是我不知道具体的语法是什么。
文本文件中的信息约为2000行,显然您不能将其存储在vba脚本中。文字如下所示
35SLFR0006350
35SLFR0026350
35SLFR0106350
BARSQR1306000
C280BD1016000
C280BD1016000_mitre
C280BD1016000_square
C280FR0006000
C280MU0006000
C280MU0026000
C280SH0006000
C280SH0006000_outer frame
C305BD0006000
C305BD0006000_mitre
C305BD0006000_square
C305BD0016000
C305BD0016000_mitre
C305BD0016000_square
C305BD2006000
C305BD2006000_mitre
C305BD2006000_square
C305FR0006000
C305MU0006000
C305MU0026000
C305MU0046000
C305SH0006000
C305SH0006000_Un E frame
C340BD1006000_mitre
C340BD1006000_Right,Left,Horizontal
C340BD1006000_Right,Left,Vertical
C340BD1006000_square
C340FR00060000
C340MU0006000
C340MU0026000
C340SH0006000
答案 0 :(得分:2)
如果要将输入文件保存为数组,则可以先读取整个文件并将其保存为一个完整的字符串。 然后,您可以将Split函数与分隔符 \ n 一起使用,以返回一个数组,其中每个元素都对应于文件的一行。
Const file As String = "<pathToFile>"
Dim ResultArray() As String
Dim tempString As String
Dim fn As Integer
fn = FreeFile()
Open file For Input As fn
While Not EOF(fn)
Line Input #fn, LineString
tempString = tempString & LineString & "\n"
Wend
ResultArray = Split(tempString, "\n")