Option Explicit
Private WithEvents mLabel As MSForms.Label
Private WithEvents mOptionButton As MSForms.OptionButton
Private WithEvents mFrame As MSForms.Frame
Private WithEvents mCheckbox As MSForms.CheckBox
Private WithEvents mToggleButton As MSForms.ToggleButton
Private WithEvents mCommandButton As MSForms.CommandButton
Private mControl As MSForms.Control
Private mTextBoxOut As MSForms.TextBox
Public Property Set Label(ByVal theLabel As MSForms.Control)
On Error GoTo errLabel:
Set mControl = theLabel
If TypeOf theLabel Is MSForms.Label Then
Set mLabel = theLabel
ElseIf TypeOf theLabel Is MSForms.CheckBox Then
Set mCheckbox = theLabel
ElseIf TypeOf theLabel Is MSForms.ToggleButton Then
Set mToggleButton = theLabel
ElseIf TypeOf theLabel Is MSForms.Frame Then
Set mFrame = theLabel
ElseIf TypeOf theLabel Is MSForms.OptionButton Then
Set mOptionButton = theLabel
ElseIf TypeOf theLabel Is MSForms.CommandButton Then
Set mCommandButton = theLabel
End If
Exit Property
errLabel:
If Err.Number = 459 Then
'For some reasons toggles and option buttons expose no events
Debug.Print theLabel.Name
Resume Next
Else
MsgBox Err.Number & " " & Err.Description
End If
End Property
Public Property Get Control()
Set Control = mControl
End Property
Private Sub mCheckbox_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Shift = 2 Then
FillTextBox
End If
End Sub
Private Sub mCommandButton_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Shift = 2 Then
FillTextBox
End If
End Sub
Private Sub mFrame_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Shift = 2 Then
FillTextBox
End If
End Sub
Private Sub mLabel_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Shift = 2 Then
FillTextBox
End If
End Sub
Public Property Set TextBoxOut(ByVal theTextBox As MSForms.TextBox)
Set mTextBoxOut = theTextBox
End Property
Public Sub FillTextBox()
If Not mTextBoxOut Is Nothing Then
mTextBoxOut = mControl.Caption
MsgBox "Mouse UP Event"
Else
MsgBox "Must set an output textbox"
End If
End Sub
Private Sub mOptionButton_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Shift = 2 Then
FillTextBox
End If
End Sub
Private Sub mToggleButton_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Shift = 2 Then
FillTextBox
End If
End Sub