|
窗体代码
- Dim cltBT As New Collection
- Private Sub SetOLEObjectControl()
- Dim oControl As Object, clsBT As ButtonClass
-
- For Each oControl In Me.Controls
- If TypeName(oControl) = "CommandButton" Then
- If oControl.Caption <> "确定" Then '不是“确定”按钮
- Set clsBT = New ButtonClass
- Set clsBT.Control = oControl
- cltBT.Add clsBT
- End If
- End If
- Next
- Set clsBT = Nothing
- End Sub
- Private Sub UserForm_Initialize()
- SetOLEObjectControl
- End Sub
复制代码
ButtonClass类代码
- Public WithEvents Control As CommandButton
-
- Private Sub Control_Click() '点击动作
- Dim vData As Variant, nRow As Integer, vList As Variant, nList As Integer, sCaption As String
-
- ReDim vList(1 To 1)
- nList = 0
- sCaption = Control.Caption
- vData = Sheet1.[L1].CurrentRegion.Value
- For nRow = 1 To UBound(vData)
- If vData(nRow, 1) Like sCaption & "*" Then
- nList = nList + 1
- ReDim Preserve vList(1 To nList)
- vList(nList) = vData(nRow, 1)
- End If
- Next
- With Control.Parent.ListBox1
- .Clear
- If nList > 0 Then .List = vList
- End With
- End Sub
复制代码 |
|