XL 2016 accès feuilles masquées par bouton

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

crown54

XLDnaute Junior
Bonjour à tous,
je fais une nouvelle fois appel à vos connaissances. J'ai un fichier excel avec plusieurs onglets. Une feuille choix d'onglet est présente et je souhaite par le biais d'un bouton pour chaque onglet le faire apparaitre et uniquement celui-là. A l'inverse quand je suis sur l'onglet en question, j'ai un bouton retour qui me permet de revenir sur la feuille choix d'onglet.
J'ai réussi à le faire via la commande suivante :
Private Sub CommandButton2_Click()
Sheets("choix onglets").Visible = True
Sheets("choix onglets").Select
End Sub


Par contre sur ma feuille de choix d'onglet, j'ai plusieurs boutons mais ça ne fonctionne pas, j'ai une erreur d'execution 1004: la méthode 'visible' de l'objet '_Worksheet' a échoué.
Voici mon code:

Private Sub CommandButton1_Click()
Dim sh As Worksheet

For Each sh In ThisWorkbook.Worksheets
With sh
If Not .Name = "
Nom onglet" Then .Visible = False
End With

Next
End Sub

Private Sub CommandButton2_Click()
Dim sh As Worksheet

For Each sh In ThisWorkbook.Worksheets
With sh
If Not .Name = "
Nom onglet Then .Visible = False
End With

Next
End Sub

Private Sub CommandButton3_Click()
Dim sh As Worksheet

For Each sh In ThisWorkbook.Worksheets
With sh
If Not .Name = "
Nom onglet" Then .Visible = False
End With

Next
End Sub

Private Sub CommandButton4_Click()
Dim sh As Worksheet

For Each sh In ThisWorkbook.Worksheets
With sh
If Not .Name = "
Nom onglet" Then .Visible = False
End With

Next
End Sub

Private Sub CommandButton5_Click()
Dim sh As Worksheet

For Each sh In ThisWorkbook.Worksheets
With sh
If Not .Name = "
Nom onglet" Then .Visible = False
End With

Next
End Sub

Private Sub CommandButton6_Click()
Dim sh As Worksheet

For Each sh In ThisWorkbook.Worksheets
With sh
If Not .Name = "
Nom onglet" Then .Visible = False
End With

Next
End Sub

Private Sub CommandButton7_Click()
Dim sh As Worksheet

For Each sh In ThisWorkbook.Worksheets
With sh
If Not .Name = "
Nom onglet" Then .Visible = False
End With

Next
End Sub

Private Sub CommandButton8_Click()
Dim sh As Worksheet

For Each sh In ThisWorkbook.Worksheets
With sh
If Not .Name = "
Nom onglet" Then .Visible = False
End With

Next
End Sub



Auriez-vous une idée de la provenance de l'erreur s'il vous plait?
Merci d'avance.
 

Pièces jointes

Dernière édition:
Bonjour @crown54

J'ai pas vu ton fichier que tu décris si bien 🤔
Mettre le code entre balise le rend beaucoup plus digeste !!! 😳
1733410624534.png
 
ça fonctionne bien quand il y a un seul bouton mais dès que j'en mets un second j'ai l'erreur indiquée avec dans le code le .Visible=False surligné en jaune.
VB:
Private Sub CommandButton2_Click()
Dim sh As Worksheet
 For Each sh In ThisWorkbook.Worksheets
  With sh
   If Not .Name = "Microscopes" Then .Visible = False
  End With
 Next
End Sub

quelqu'un pourrait me dire comment fonctionne cette commande et pourquoi quand j'en mets plusieurs de ce style cela ne marche pas?
Merci et bonne après-midi
 
Bonjour
l'erreur provient certainement du fait que si ton code est amené à masquer la SEULE feuille encore affichée.. plantage...

plutot qu'avoir 10 boutons.. pourquoi ne pas avoir UN seul bouton qui affiche la feuille que tu as selectionnée dans la liste

cf PJ
 

Pièces jointes

alors
tu mets plusieurs boutons avec chacun un nom spécifique (celui de la feuille à afficher)
et UNE seule macro affectée à tous les boutons
lorsque tu cliques sur un des boutons, la macro regarde le nom du bouton qui l'a appelée.. et affiche la feuille adéquate
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

  • Question Question
Microsoft 365 worksheet_change
Réponses
29
Affichages
234
Retour