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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28137955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 05:57:39  来源:igfitidea点击:

How to get all listbox item using word vba?

excelvbams-word

提问by Abu Nayeem

I need to get all the list-items of a listbox not only selected. For example I have a list box with following list item:

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

A
C
K
L

How I can show them all in Immediate window?

如何在立即窗口中显示它们?

回答by blckbird

You can loop through all by using the column property of a ListBox. This Column(index, row)property return the value of the ListBox item at a specific index and row. For your simple ListBox the index will be 0. However, the row must be variable. For example you can use a for loop to get all the values of the ListBox.

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

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

回答by Abu Nayeem

Sub get_all_list_item()

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

End Sub