如何在程序生成的控件上调用函数?

时间:2015-11-18 19:46:15

标签: excel vba listbox

我已经在单击按钮时按程序创建的一系列单元格中添加了3列列表框。列表框是3列并且包含大量数据,因此我使用GotFocus()和LostFocus()来展开和折叠它们以便所有项目都可见,但这是我手动创建的列表框。如何让生成的Listbox具有此行为?

Public Sub CreateListbox()
 Dim rCell As Range
    Dim rRng As Range
    Set rRng = ActiveSheet.Range("AA3:AA45")
    For Each rCell In rRng.Cells
        Set oLISTBOX = ActiveSheet.OLEObjects.Add(classtype:="Forms.ListBox.1")
With oLISTBOX
        .Object.IntegralHeight = False
        .Object.Font.Size = 11
        .Top = rCell.Top
        .Left = rCell.Left
        .Width = rCell.Width
        .Height = rCell.Height
        .LinkedCell = rCell.Address
        .ListFillRange = "ValSocDeterm."
        .Object.ColumnCount = 3
        .MultiSelect = 1
    End With

    Next rCell
End Sub

0 个答案:

没有答案