AW: If Click in TextBox Then
18.02.2019 17:03:36
Nepumuk
Hallo Tobi,
es gibt keine dummen Fragen. Nur dumme Antworten.
Im UserForm:
Private Sub Userform_Initialize()
Dim objTextBoxClass As clsTextbox
Dim objControl As Control
Set TextBoxClassCollection = New Collection
For Each objControl In Controls
If TypeOf objControl Is MSForms.TextBox Then
Set objTextBoxClass = New clsTextbox
With objTextBoxClass
Set .CommandButton(1) = CommandButton1
Set .CommandButton(2) = CommandButton2
Set .CommandButton(3) = CommandButton4
Set .ListBox = ListBox1
Set .TextBox = objControl
Call TextBoxClassCollection.Add(Item:=objTextBoxClass)
End With
Set objTextBoxClass = Nothing
End If
Next
Dim lzeile As Long, arrList
With Tabelle1
arrList = .Range(.Cells(2, 4), .Cells(.Rows.Count, 5).End(xlUp))
End With
For lzeile = 1 To UBound(arrList)
arrList(lzeile, 1) = arrList(lzeile, 2) & ", " & arrList(lzeile, 1)
arrList(lzeile, 2) = lzeile + 1
Next
ListBox1.List = arrList
ListBox1.Selected(0) = True
End Sub
Im Klassenmodul:
Option Explicit
Private WithEvents mobjTextBox As MSForms.TextBox
Private maobjCommandButton(1 To 3) As MSForms.CommandButton
Private mobjListbox As MSForms.ListBox
Private Sub Class_Terminate()
Set mobjTextBox = Nothing
Set mobjListbox = Nothing
Erase maobjCommandButton
End Sub
Friend Property Get TextBox() As MSForms.TextBox
Set TextBox = mobjTextBox
End Property
Friend Property Set TextBox(ByRef probjTextBox As MSForms.TextBox)
Set mobjTextBox = probjTextBox
End Property
Friend Property Get CommandButton(ByVal pvlngIndex As Long) As MSForms.CommandButton
Set CommandButton = maobjCommandButton(pvlngIndex)
End Property
Friend Property Set CommandButton(ByVal pvlngIndex As Long, ByRef probjCommandButton As MSForms.CommandButton)
Set maobjCommandButton(pvlngIndex) = probjCommandButton
End Property
Friend Property Get ListBox() As MSForms.ListBox
Set ListBox = mobjListbox
End Property
Friend Property Set ListBox(ByRef probjListBox As MSForms.ListBox)
Set mobjListbox = probjListBox
End Property
Private Sub mobjTextBox_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = xlPrimaryButton Then Call DisableCommandButtons
End Sub
Private Sub DisableCommandButtons()
Dim ialngIndex As Long
For ialngIndex = LBound(maobjCommandButton) To UBound(maobjCommandButton)
CommandButton(ialngIndex).Enabled = False
Next
ListBox.Enabled = False
End Sub
Ich hatte noch einen Schreibfehler im Code des Klassenmoduls. Also bitte den kompletten Code kopieren.
Gruß
Nepumuk