Microsoft 365 Un commandbutton avec 2 macros

natorp

XLDnaute Accro
Bonjour à toutes et tous

J'aimerais affecter à un bouton de commande 2 macros, que le bouton se comporte comme une bascule :
Je clique 1 fois dessus et j'active une macro, je re-clique dessus et j'active une autre macro

Merci pour votre attention et votre aide, cordialement, Gérard
 

Pièces jointes

  • Classeur4.xlsm
    22.4 KB · Affichages: 3
Solution
Avec un CommandButton :
VB:
Private Sub CommandButton1_Click()
   If CommandButton1.Caption Like "Afficher *" Then
      AfficheLignes
      CommandButton1.Caption = "Masquer toutes les lignes"
   Else
      MasqueLignes
      CommandButton1.Caption = "Afficher toutes les lignes"
      End If
   End Sub

Dranreb

XLDnaute Barbatruc
Avec un CommandButton :
VB:
Private Sub CommandButton1_Click()
   If CommandButton1.Caption Like "Afficher *" Then
      AfficheLignes
      CommandButton1.Caption = "Masquer toutes les lignes"
   Else
      MasqueLignes
      CommandButton1.Caption = "Afficher toutes les lignes"
      End If
   End Sub
 

cp4

XLDnaute Barbatruc
Bonjour Dranreb ;), TooFatBoy ;), Chris ;), Natorp :)

@natorp : Ce n'était pas si compliqué. Tu aurais pu trouver tous seul. Les amis t'avaient bien mis sur la bonne voie.
VB:
Private Sub CommandButton1_Click()
   If CommandButton1.Caption = "Afficher toutes les lignes" Then
      AfficheLignes
      CommandButton1.Caption = "Masquer toutes les lignes"
   ElseIf CommandButton1.Caption = "Masquer toutes les lignes" Then
      MasqueLignes
      CommandButton1.Caption = "Afficher toutes les lignes"
   End If
End Sub
 

Discussions similaires

Membres actuellement en ligne

Aucun membre en ligne actuellement.

Statistiques des forums

Discussions
312 229
Messages
2 086 426
Membres
103 206
dernier inscrit
diambote