Private Sub Command1_Click() toto 1 End Sub Private Sub Command2_Click() toto 2 End Sub Private Sub toto(indice As Integer) MsgBox Controls("Command" & indice).Name End Sub
Private Sub Command1_Click() toto 1 End Sub Private Sub Command2_Click() toto 2 End Sub Private Sub toto(indice As Integer) Dim titi As Object Set titi = Controls("Command" & indice) MsgBox titi.Name End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub TextBox1_KeyPress(ByVal keyascii As MSForms.ReturnInteger) forcer_numerique 1, keyascii End Sub Private Sub TextBox2_KeyPress(ByVal keyascii As MSForms.ReturnInteger) forcer_numerique 2, keyascii End Sub Private Sub TextBox3_KeyPress(ByVal keyascii As MSForms.ReturnInteger) forcer_numerique 3, keyascii End Sub Private Sub forcer_numerique(indice As Integer, keyascii As MSForms.ReturnInteger) If Not IsNumeric(Chr(keyascii)) Then keyascii = 0 End Sub
Private Sub Controls("txt_joueur_RPE_1")_KeyPress(ByVal keyascii As MSForms.ReturnInteger) ... End Sub
Private Sub UserForm_Activate() Dim nb As Integer, obj As Control, i As Integer Me.Move 0, 0, 500, 400 Dim boitetexte As MSForms.Control On Error Resume Next For i = 0 To 2 Set boitetexte = Me.Controls("" & i) If boitetexte Is Nothing Then Set boitetexte = Me.Controls.Add("Forms.TextBox.1", "toto(" & i & ")", True) With boitetexte .Caption = "Ma textbox" & i .Top = 20 * i .Left = 100 * i .Height = 20 .Width = 100 End With Else MsgBox "existe déjà !" End If Set boitetexte = Nothing Next For Each obj In Me.Controls If obj.Name Like "toto*" Then nb = nb + 1 ReDim Preserve mesTextBoxes(1 To nb) Set mesTextBoxes(nb).TextBoxEvents = obj End If Next obj Set obj = Nothing End Sub
Option Explicit Public WithEvents TextBoxEvents As MSForms.TextBox Private Sub TextBoxEvents_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Dim index As Integer, qui As String qui = UserForm1.ActiveControl.Name index = Val(Mid(qui, InStr(qui, "(") + 1)) Select Case index Case 0 If KeyAscii <> 8 And Not IsNumeric(Chr(KeyAscii)) Then KeyAscii = 0 End If Case 1 If IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 Then KeyAscii = 0 End If Case 2 KeyAscii = Asc(UCase(Chr(KeyAscii))) End Select End Sub
Public mestextboxes() As New Classe1