s="qweqe~drtd~edyte~rert`qw3eqe~drtd~edyt3e~rert`qw3eqe~drtd~3edyte~rert"
ListBoxArr = Split(Mid(s, 2), "`")
For Li = LBound(ListBoxArr) To UBound(ListBoxArr)
ListBoxArr2 = Split(ListBoxArr(Li), "~")
For Ly = LBound(ListBoxArr2) To UBound(ListBoxArr2)
With ListBox1
.ColumnCount = 4
.ColumnWidths = "50;50;50;50"
.AddItem
.List(Ly, 0) = ListBoxArr2(Ly)
.List(Ly, 1) = ListBoxArr2(Ly)
.List(Ly, 2) = ListBoxArr2(Ly)
.List(Ly, 3) = ListBoxArr2(Ly)
End With
Next Ly
Next Li
我收到错误运行时错误380 Could not set the List property. Invalid property value
怎么了?我需要从数组中获取4列列表框值
EMBED("Forms.ListBox.1";"")
调试
.List(Ly, 1) = ListBoxArr2(Ly)
答案 0 :(得分:0)
One For / Next将执行
在每次革命中,您将一组从第1维拆分为第二维,然后立即在框中添加记录
请注意,.Add
ListBox1.Clear ' as a precaution to not double load
s = "qweqe~drtd~edyte~rert`qw3eqe~drtd~edyt3e~rert`qw3eqe~drtd~3edyte~rert"
ListBoxArr = Split(Mid(s, 2), "`")
For Li = LBound(ListBoxArr) To UBound(ListBoxArr)
ListBoxArr2 = Split(ListBoxArr(Li), "~")
With ListBox1
.ColumnCount = 4
.ColumnWidths = "50;50;50;50"
.AddItem ListBoxArr2(0), Li
.List(Li, 1) = ListBoxArr2(1)
.List(Li, 2) = ListBoxArr2(2)
.List(Li, 3) = ListBoxArr2(3)
End With
Next Li
回复评论:
确保使用ActiveX对象(不是Forms对象);此外,我有以下参考(VBA窗口/菜单:工具/参考);你可能想确保你也有它们