Private Sub UserForm_Initialize() Dim Wsh As Worksheet, Ind As Integer Dim monBouton As Object Ind = 1 For Each Wsh In ThisWorkbook.Worksheets ReDim Preserve MesBoutons(1 To Ind) Set monBouton = Me.Controls.Add("Forms.CommandButton.1", "Btn" & Ind, True) With monBouton .Name = "Bouton " & Ind .Caption = Ind .Move Ind * 50, 0, 50, 50 Set MesBoutons(Ind).BoutonEvents = monBouton End With Set monBouton = Nothing Ind = Ind + 1 Next Wsh Me.Width = Ind * 50 + 50 End Sub
Public MesBoutons() As New Classe1
Public WithEvents BoutonEvents As MSForms.CommandButton Private Sub BoutonEvents_Click() MsgBox BoutonEvents.Name End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Public Sub BoutonOK2_Click()
Application.ScreenUpdating = False
Dim Reponse As String
Nbr_AtomesPF = TextBox1.Value
If Nbr_AtomesPF = 1 Then
Reponse = MsgBox("Êtes-vous certain(e) de vouloir continuer avec " & Nbr_AtomesPF & " atome ?", vbYesNo, "Nombre d'atomes !")
Else
Reponse = MsgBox("Êtes-vous certain(e) de vouloir continuer avec " & Nbr_AtomesPF & " atomes ?", vbYesNo, "Nombre d'atomes !")
End If
If Reponse = vbYes Then
UserForm2.Hide
UserForm1.Show
End If
Application.ScreenUpdating = True
End Sub
Private Sub SpinButton1_SpinDown()
TextBox1.Value = TextBox1.Value - 1
End Sub
Private Sub SpinButton1_SpinUp()
TextBox1.Value = TextBox1.Value + 1
End Sub
Private Sub UserForm_Initialize()
TextBox1.Value = 1
TextBox1.FontSize = 14
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
End
End If
End Sub
Public Sub BoutonOK2_Click()
Application.ScreenUpdating = False
Dim Reponse As String
Nbr_AtomesPF = TextBox1.Value
If Nbr_AtomesPF = 1 Then
Reponse = MsgBox("Êtes-vous certain(e) de vouloir continuer avec " & Nbr_AtomesPF & " atome ?", vbYesNo, "Nombre d'atomes !")
Else
Reponse = MsgBox("Êtes-vous certain(e) de vouloir continuer avec " & Nbr_AtomesPF & " atomes ?", vbYesNo, "Nombre d'atomes !")
End If
If Reponse = vbYes Then
UserForm2.Hide
UserForm1.Show
End If
Application.ScreenUpdating = True
End Sub
Private Sub SpinButton1_SpinDown()
TextBox1.Value = TextBox1.Value - 1
End Sub
Private Sub SpinButton1_SpinUp()
TextBox1.Value = TextBox1.Value + 1
End Sub
Private Sub UserForm_Initialize()
TextBox1.Value = 1
TextBox1.FontSize = 14
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
End
End If
End Sub
Public MesBoutons() As New Classe1
Public Nbr_AtomesPF As Integer
Public choix As Integer
'Public r as integer
'Public d As Integer
'Public Inc As Integer
'Public Molecule As Double
'Public masseref As Double
'Public refmol As Double
'Public moleref As Double
Sub Calculmasse()
UserForm2.Show
Unload UserForm1
Unload UserForm2
End Sub
Public WithEvents BoutonEvents As MSForms.CommandButton
Private Sub BoutonEvents_Click()
' Dim opt As Control
' Dim num As Integer
'
' Set opt = UserForm1.Controls.Add("Forms.ComboBox.1")
' With opt
' .Name = "Dop" & i
' .RowSource = "Classification!B2:B119"
' .Left = 30 + X
' .Height = 20
' .Width = 50
' .Top = 30
' .ListRows = 20
' .ListWidth = 50
' .Font.Bold = True
' .Font.Name = "Calibri"
' .Font.Size = 14
' End With
End Sub
7 nov. 2014 à 12:21
Je me suis rendu compte que cette méthode n'est peut être pas super adaptée à ton cas...
En effet, dans ce code, tous les boutons font la même action. Ce n'est sans doute pas ton cas...