Linux 拨号vps windows公众号手机端

vba列表框的值如何提取出来

lewis 7年前 (2019-01-27) 阅读数 12 #程序编程
文章标签 vba

要提取VBA列表框的值,可以使用以下方法:

  1. 使用List属性:使用List属性可以直接获取整个列表框中的所有值。例如:
Dim i As Integer
Dim selectedValues As String
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
selectedValues = selectedValues & ListBox1.List(i) & ", "
End If
Next i
selectedValues = Left(selectedValues, Len(selectedValues) - 2) '去掉最后的逗号和空格
MsgBox selectedValues

上述代码会将选中的项的值以逗号分隔的形式存储在selectedValues字符串变量中,并通过MsgBox函数显示出来。

  1. 使用Value属性:如果只需要获取选中的某一项的值,可以使用Value属性。例如:
Dim selectedValue As String
If ListBox1.ListIndex <> -1 Then
selectedValue = ListBox1.Value
MsgBox selectedValue
End If

上述代码会判断是否选择了某一项,如果选择了,则将该项的值存储在selectedValue字符串变量中,并通过MsgBox函数显示出来。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门