Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Excel > Macros et VBA Excel
Macros et VBA Excel Vos questions relatives aux macros Excel, à l'utilisation de VBA et à l'automatisation de vos classeurs Excel.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 05/09/2011, 12h52   #1
Membre expérimenté
 
Inscription : décembre 2006
Messages : 645
Détails du profil
Informations forums :
Inscription : décembre 2006
Messages : 645
Points : 595
Points : 595
Envoyer un message via Skype™ à ESVBA
Par défaut Comment réinitialiser CommandBars("Cell")

Bonjour à tous,

Je veux un menu contextuel particulier pour une feuille en particulier.

Je fais un appel à des procédures :
Code :
1
2
3
4
5
6
7
Private Sub Worksheet_Activate()
     Call Creation_popup 
End Sub
 
Private Sub Worksheet_Deactivate()
    Call Suppression_popup
End Sub
Le code pour modifier le menu contextuel des cellules est du genre :
Code :
1
2
3
4
5
6
7
8
9
10
11
Sub Creation_popup
Set Cbar = CommandBars("Cell")
Set Cbut = Cbar.Controls.Add(msoControlButton)
For i = 1 to 3
  With Cbut
    .Caption = "2P"
    .OnAction = "CR" & i 
    .PasteFace 
  End With
Next i
End Sub
Le code pour retirer mes ajouts est le suivant :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
Sub Suppression_popup()
    Dim i As Integer

    On Error Resume Next
    For i = 1 To 3
        With Application.CommandBars("Cell")
            .Controls(ICICICICICIC).Delete
        End With
    Next i
    
    On Error GoTo 0
End Sub
Premier problème :
Mais je ne vois pas quel nom donner à mon contrôle (avec quelle propriété) ?

Second problème :
L'utilisation de
Code :
Application.CommandBars("cell").Reset
remet bien le contrôle à zéro sauf que je n'ai plus accès à la hauteur de ligne et la largeur de colonne dans le menu contextuel.



ESVBA
ESVBA est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/09/2011, 13h35   #2
Membre Expert
 
Homme Hervé Silve
Inscription : août 2010
Messages : 773
Détails du profil
Informations personnelles :
Nom : Homme Hervé Silve
Localisation : France

Informations forums :
Inscription : août 2010
Messages : 773
Points : 2 093
Points : 2 093
Bonjour,

Je ne sais pas si c'est ce que tu cherche mais voilà, j'ai adapter tes proc :
Code :
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
 
Sub Creation_popup()
 
    Dim Cbar As CommandBar
    Dim Cbut As CommandBarButton
    Dim Tbl
    Dim I As Integer
 
    'tableau pour le FaceID
    Tbl = Array(3, 23, 364)
    Set Cbar = CommandBars("Cell")
 
    For I = 1 To 3
 
        'ici, le bouton est créé 3 fois
        Set Cbut = Cbar.Controls.Add(msoControlButton, Tbl(I - 1))
 
        With Cbut
 
            .Caption = "2P" & I
            .OnAction = "CR" & I
 
        End With
 
    Next I
 
End Sub
 
Sub Suppresion_popup()
 
    Dim Cbar As CommandBar
    Dim I As Integer
 
    Set Cbar = CommandBars("Cell")
 
    On Error Resume Next
 
    For I = 1 To 3
 
        With Cbar
 
            .Controls("2P" & I).Delete
 
        End With
    Next I
 
End Sub
Hervé.
Theze est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 05/09/2011, 14h23   #3
Membre expérimenté
 
Inscription : décembre 2006
Messages : 645
Détails du profil
Informations forums :
Inscription : décembre 2006
Messages : 645
Points : 595
Points : 595
Envoyer un message via Skype™ à ESVBA
J'en conclu :

Merci. C'est Résolu.

ESVBA
ESVBA est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 17h06.


 
 
 
 
Partenaires

Hébergement Web