ListBox 控制項、Column、ColumnCount、List 屬性範例
The following example loads a two-dimensional array with data and, in turn, loads two ListBox controls using the Column and List properties. 注意 Column 屬性在載入程序中將轉置陣列元素。
若要使用本範例,請將此範例程式碼複製到表單的宣告部分中。 Make sure that the form contains two ListBox controls named ListBox1 and ListBox2.
Dim MyArray(6,3)
Private Sub UserForm_Initialize()
Dim i As Single
'The 1st list box contains 3 data columns
ListBox1.ColumnCount = 3
'The 2nd box contains 6 data columns
ListBox2.ColumnCount = 6
'Load integer values into first column of MyArray
For i = 0 To 5
MyArray(i, 0) = i
Next i
'Load columns 2 and three of MyArray
MyArray(0, 1) = "Zero"
MyArray(1, 1) = "One"
MyArray(2, 1) = "Two"
MyArray(3, 1) = "Three"
MyArray(4, 1) = "Four"
MyArray(5, 1) = "Five"
MyArray(0, 2) = "Zero"
MyArray(1, 2) = "Un ou Une"
MyArray(2, 2) = "Deux"
MyArray(3, 2) = "Trois"
MyArray(4, 2) = "Quatre"
MyArray(5, 2) = "Cinq"
'Load data into ListBox1 and ListBox2
ListBox1.List() = MyArray
ListBox2.Column() = MyArray
End Sub
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。