Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

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
Bonjour.
Si, plutôt que CommandButton, un ActiveX ToggleButton ne vous convenait pas (pourquoi ?), vous pourriez aussi jouer sur son Caption et le changer alternativement à chaque exécution.
 

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

Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…