Hi,
wie Gast7777, bereits schrieb, brauchst für jede Textbox ein eigenes Ereignis
1 2 3 | Private Sub TextBox10_MouseMove( ByVal Button As Integer , ByVal Shift As Integer , ByVal X As Single , ByVal Y As Single )
Label7.Caption = "Textbox 10 Mouseover"
End Sub
|
und am Ende: deiner 20 Ereignisse
1 2 3 | Private Sub UserForm_MouseMove( ByVal Button As Integer , ByVal Shift As Integer , ByVal X As Single , ByVal Y As Single )
Label7.Caption = ""
End Sub
|
oder wenn du es wie im Fragebeispiel per Schleife machen willst dann so: Erstelle zunächst ein Klassenmodul z.B. "Klasse1"
gib dort z.B. diesen Code ein um Label7.Caption anzusprechen:
1 2 3 4 5 | Public WithEvents tbx As MSForms.TextBox
Private Sub tbx_MouseMove( ByVal Button As Integer , ByVal Shift As Integer , ByVal X As Single , ByVal Y As Single )
UserForm1.Label7 = tbx.Name & " Mousover"
End Sub
|
Damit hast du nur ein Event für alle 20 Textboxen.
Anschließend musst du die Textboxen im Userform nur noch mit dem Event verbinden. Das machst du mit dem Initialize-Ereignis. Gib dazu im Userform diesen Code ein.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Dim tbevt() As New Klasse1
Private Sub UserForm_Initialize()
For i = 1 To 20
ReDim Preserve tbevt(i)
Set tbevt(i).tbx = Me .Controls( "Textbox" & i)
Next i
End Sub
Private Sub UserForm_MouseMove( ByVal Button As Integer , ByVal Shift As Integer , ByVal X As Single , ByVal Y As Single )
Label7.Caption = ""
End Sub
|
PS. Label 7 sollte natürlich immer Visible sein sonst einfach im Klassenmodul ergänzen.
Gruß Mr. K.
|