更改多个文本框的事件

时间:2016-01-22 04:41:19

标签: vba

我已经使用类Module为多个文本框编写了单个更改事件,但我观察到的是在我的' oControl' Me.Controls给出False而不是控件。还有其他办法吗?

Private m_oCollectionOfEventHandlers As Collection
Private Sub UserForm_Initialize()

    Set m_oCollectionOfEventHandlers = New Collection
    Dim oControl As Control
    For Each oControl In Me.Controls
        If TypeName(oControl) = "TextBox" Then
            Dim oEventHandler As Class1
            Set oEventHandler = New Class1
            Set oEventHandler.TextBox = oControl
            m_oCollectionOfEventHandlers.Add oEventHandler
        End If

    Next oControl
End Sub

'CLASS MODULE
Private WithEvents m_oTextBox As TextBox
Public Property Set TextBox(ByVal oTextBox As TextBox)
    Set m_oTextBox = oTextBox
End Property
Private Sub m_oTextBox_Change()
MsgBox ("Hello")
End Sub

0 个答案:

没有答案