macro bouton active x

mimi1958

XLDnaute Junior
bonjour a tous

Je voudrai savoir si il est possible d'affecter une macro a un bouton active x ?
sur ma feuille 1 exel j'ai bouton 1 , bouton 2, bouton 3 , bouton 4
quand je clic sur bouton 1 il devient bleu , quand je clic sur bouton 2 il devient bleu et le bouton 1 passe au vert ainsi de suite.
maintenant sur le bouton 1 ( feuille 1 ) , je vourdrai rajouter en plus de la couleur , lui attribuer une macro pour aller sur la feuille 2
est ce possible ?
voici les codes que j'ai utilise :

Private Sub CommandButton1_Click()
Range("A1") = "Oui"
CommandButton1.BackColor = RGB(0, 0, 240)
CommandButton2.BackColor = RGB(0, 240, 0)

End Sub

Private Sub CommandButton2_Click()
Range("A1") = "Non"
CommandButton1.BackColor = RGB(0, 240, 0)
CommandButton2.BackColor = RGB(0, 0, 240)
End Sub

Private Sub CommandButton3_Click()
Range("A1") = "Non"
CommandButton2.BackColor = RGB(0, 240, 0)
CommandButton3.BackColor = RGB(0, 0, 240)
End Sub

Private Sub CommandButton4_Click()
Range("A1") = "Non"
CommandButton3.BackColor = RGB(0, 240, 0)
CommandButton4.BackColor = RGB(0, 0, 240)
End Sub

Private Sub CommandButton5_Click()
Range("A1") = "Non"
CommandButton4.BackColor = RGB(0, 240, 0)
CommandButton5.BackColor = RGB(0, 0, 240)
CommandButton5.BackColor = RGB(0, 240, 0)
End Sub

Merci pour votre collaboration .( je vous joint lefichier
 

Pièces jointes

  • ESSAI COULEUR BOUTON.xlsm
    32.4 KB · Affichages: 21

M12

XLDnaute Accro
Bonjour
tu rajoutes simplement dans la partie de la macro du bouton 1
Sheets("nom de la feuille").activate

Code:
Private Sub CommandButton1_Click()
TOUR1
Range("A1") = "Oui"
CommandButton1.BackColor = RGB(0, 0, 240)
CommandButton2.BackColor = RGB(0, 240, 0)
Sheets("sheet2").Activate
 

mimi1958

XLDnaute Junior
impec ca marche merci
encore une question
quand je suis sur le dernier bouton et que je clique dessus , il devient bleu
mais quand je reclick sur le bouton 1 comment faire pour que le bouton 4 deviennet vert
une sorte de boubcle en fait
je n'y suis pas arrive
merci par avance

codes :
Private Sub CommandButton1_Click()
Range("A1") = "Oui"
CommandButton1.BackColor = RGB(0, 0, 240)
CommandButton2.BackColor = RGB(0, 240, 0)
Sheets("sheet2").Activate
End Sub

Private Sub CommandButton2_Click()
Range("A1") = "Non"
CommandButton1.BackColor = RGB(0, 240, 0)
CommandButton2.BackColor = RGB(0, 0, 240)
Sheets("sheet3").Activate
End Sub

Private Sub CommandButton3_Click()
Range("A1") = "Non"
CommandButton2.BackColor = RGB(0, 240, 0)
CommandButton3.BackColor = RGB(0, 0, 240)
End Sub

Private Sub CommandButton4_Click()
Range("A1") = "Non"
CommandButton3.BackColor = RGB(0, 240, 0)
CommandButton4.BackColor = RGB(0, 0, 240)
End Sub

Private Sub CommandButton5_Click()
Range("A1") = "Non"
CommandButton4.BackColor = RGB(0, 240, 0)
CommandButton5.BackColor = RGB(0, 0, 240)
End Sub
 

M12

XLDnaute Accro
Re,

Comme ceci
Code:
Private Sub CommandButton1_Click()
TOUR1
Range("A1") = "Oui"
CommandButton1.BackColor = RGB(0, 0, 240)
CommandButton2.BackColor = RGB(0, 240, 0)
CommandButton3.BackColor = RGB(0, 240, 0)
CommandButton4.BackColor = RGB(0, 240, 0)
Sheets("sheet2").Activate
End Sub

Private Sub CommandButton2_Click()
Range("A1") = "Non"
CommandButton2.BackColor = RGB(0, 0, 240)
CommandButton1.BackColor = RGB(0, 240, 0)
CommandButton3.BackColor = RGB(0, 240, 0)
CommandButton4.BackColor = RGB(0, 240, 0)

End Sub

Private Sub CommandButton3_Click()
Range("A1") = "Non"
CommandButton3.BackColor = RGB(0, 0, 240)
CommandButton1.BackColor = RGB(0, 240, 0)
CommandButton2.BackColor = RGB(0, 240, 0)
CommandButton4.BackColor = RGB(0, 240, 0)

End Sub

Private Sub CommandButton4_Click()
Range("A1") = "Non"
CommandButton4.BackColor = RGB(0, 0, 240)
CommandButton1.BackColor = RGB(0, 240, 0)
CommandButton2.BackColor = RGB(0, 240, 0)
CommandButton3.BackColor = RGB(0, 240, 0)

End Sub

Private Sub CommandButton5_Click()
Range("A1") = "Non"
CommandButton4.BackColor = RGB(0, 240, 0)
CommandButton5.BackColor = RGB(0, 0, 240)
CommandButton5.BackColor = RGB(0, 240, 0)
End Sub
 

Discussions similaires

Réponses
0
Affichages
177
Réponses
7
Affichages
410

Statistiques des forums

Discussions
312 500
Messages
2 089 010
Membres
104 004
dernier inscrit
mista