1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| Private Sub btnModifier_Click()
Dim btn As Button
If MsgBox("Etes-vous sûr de vouloir modifier le nom du bouton ?", _
vbYesNo, "Demande de confirmation") = vbYes Then
'--- parcourir les boutons pour trouver le premier qui a le nom du bouton sélectionné
For Each btn In ActiveSheet.Buttons '--- boutons "Contrôles de formulaire" (et pas "Contrôles ActiveX")
Debug.Print btn.Name
If btn.Caption = Me.CboBouton Then
btn.Caption = Me.NouveauNom
'Debug.Print Me.CboBouton.Column(1) '--- n° de la ligne
Worksheets("Listes").Range("C" & Me.CboBouton.Column(1)) = Me.NouveauNom
UserForm_Initialize
Me.NouveauNom = ""
End If
Next btn
If Me.NouveauNom <> "" Then
MsgBox "Changement non réalisé: sur cette feuille" & vbLf & _
"il n'y a pas de bouton ayant '" & "'" & Me.CboBouton & "'" & vbLf & _
"comme libellé!", _
vbExclamation, "Anomalie"
End If
End If
End Sub
'--- le déroulant CboList comporte 2 colonnes (ColumnCount: 2, ColumnWidths: 100pt ;0pt)
'--- n° des colonnes: 0 = première, 1 = deuxième
Private Sub UserForm_Initialize()
Dim wshListes As Worksheet
Dim Ligne As Long
Set wshListes = Worksheets("Listes")
Me.CboBouton.Clear
Ligne = 2
While wshListes.Range("A" & Ligne) <> ""
If wshListes.Range("A" & Ligne) = ActiveSheet.Name Then
If wshListes.Range("B" & Ligne) = "Divers" Then
'Debug.Print Ligne, wshListes.Range("A" & Ligne), wshListes.Range("C" & Ligne)
Me.CboBouton.AddItem wshListes.Range("C" & Ligne) '--- ajoute nouvelle valeur (en colonne n°0)
Me.CboBouton.Column(1, Me.CboBouton.ListCount - 1) = Ligne '--- complète avec n° de la ligne (en colonne n°1)
'Debug.Print Me.CboBouton.ListCount, Me.CboBouton.ListIndex
End If
End If
Ligne = Ligne + 1
Wend
Set wshListes = Nothing
'--- note: pas de vérification que les boutons existent vraiment dans les feuilles
End Sub |
Partager