【发布时间】:2016-05-31 12:05:15
【问题描述】:
下午好,
我想在数组中添加一个长字符串,例如“OA_OB_OC_OD_n1”。然后使用 Split 函数将其分成几个部分,并将它们放入我的工作表中,例如: OA|OB|OC|OD|n1|
这是我的代码(所有的 Dim 都已完成):
Public Sub Boutton_Importer_Click()
list_de_controle = "TEXT;" & listPath
Open listPath For Input As #1
'to read a list which contains the name of files I want to open
Do While Not EOF(1)
Line Input #1, nom_de_Fich 'read the name of file
WrdArray() = Split(nom_de_Fich, "_") 'here is the problem
For Each wrd In WrdArray()
ActiveCell.Value = wrd
ActiveCell.Offset(0, 1).Select
Next wrd
Open nom_de_Fich For Input As #2 'open the file
Insérer_contenu 'I have a function here to read the contents
Close #2
ActiveCell.Offset(1, 0).Select
ActiveCell.End(xlToLeft).Select
Loop
Close #1
结束子
如果我改变这部分:
Line Input #1, nom_de_Fich 'read the name of file
WrdArray() = Split(nom_de_Fich, "_") 'here is the problem
For Each wrd In WrdArray()
ActiveCell.Value = wrd
ActiveCell.Offset(0, 1).Select
Next wrd
进入:
Line Input #1, nom_de_Fich 'read the name of file
ActiveCell.Value = nom_de_Fich
ActiveCell.Offset(0, 1).Select
效果很好。所以我不知道如何解决这个问题。 提前谢谢!
【问题讨论】:
-
您收到什么错误信息?虽然我通常不会在使用数组时写
()(仅在维度上),但我写了一个快速测试用例,使用你的语法它不会失败。 -
抱歉耽搁了。错误是预期的数组。我认为这意味着数组仍然是空的?
-
我写了一个较小的,在下面的评论中。如果可以,请检查一下。