VBA控件ListBox的BoundColumn和TextColumn⽤法,Value
和T。。。
在使⽤Excel编写VBA程序时,⽤到ListBox,然后研究了下它的所有属性。其实这个控件功能很不好⽤,太⽼了,最重要的是还不⽀持⿏标滚轮,很不好操作,但是考虑到兼容性,还是使⽤它。
其实读取、写⼊数据⽤ListBox.List已经⾜够了,⽽BoundColumn和TextColumn主要是⽤于读取数据,有什么鸟⽤?我也不是很清楚,但是可以像下⾯这样⽤。这两个参数相当于设置了列的索引(j),只需选中⾏(i)即可读取对应的数据List(i,j)。其中,BoundColumn与Value关联;TextColumn与Text 关联。
Private Sub CommandButton1_Click()
ListBox1.ListIndex = 0'选中第⼀⾏,不选中的话,读取不到数值,
ListBox1.BoundColumn = 2'该属性从1开始计数,即现在对应的列索引为1;默认值为1
ListBox1.TextColumn = 3'该属性从1开始计数,即现在对应的列索引为2;默认值为-1,如果不赋值将⽆法读取数据
Debug.Print "value = " & ListBox1.Value '输出 value = 0,1
Debug.Print "text = " & ListBox1.Text  '输出 text = 0,2
End Sub
Private Sub UserForm_Initialize()
Dim i As Integer
Dim j As Integer
ListBox1.ColumnCount = 5'设置5列
i = 0
While i < 10
ListBox1.AddItem
j = 0
While j < ListBox1.ColumnCount
ListBox1.List(i, j) = CStr(i) & "," & CStr(j)
j = j + 1
Wend
i = i + 1
Wend
End Subvba listbox控件详解
关键词:VBA  ListBox BoundColumn TextColumn Value Text 说明 参数 使⽤⽅法 Excel

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。