如何使用word vba获取所有列表框项?

时间:2015-01-25 15:16:00

标签: excel vba ms-word

我需要不仅选择列表框的所有列表项。 例如,我有一个列表框,其中包含以下列表项:

A
C
K
L

如何在立即窗口中显示所有内容?

2 个答案:

答案 0 :(得分:3)

您可以使用ListBox的column属性遍历所有。此Column(index, row)属性返回特定索引和行的ListBox项的值。对于简单的ListBox,索引将为0.但是,该行必须是可变的。例如,您可以使用for循环来获取ListBox的所有值。

for i = 0 to ListBox1.ListCount-1
    MsgBox(ListBox1.Column(0, i))
next i

答案 1 :(得分:1)

Sub get_all_list_item()

For i=0 to Listbox1.ListCount-1
Debug.Print Listbox1.List(0)
Next i

End Sub