Liste de choix perso
Catégorie : Souris
Publié par veriland le 07-Aug-2013 16:30
clic souris
 

partie à placer dans ThisWorkbook

module


Option Explicit
'VériTi Juillet 2004
'créer le menu contextuel à l'ouverture
Private Sub Workbook_Open()
    Call Creer_MenuContextuel
End Sub

'enlever le menu contextuel à la fermeture
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Call Enleve_MenuContextuel
End Sub


'partie à placer dans un module de feuille
 
module


Option Explicit

Private Sub Worksheet_BeforeRightClick(ByVal Target As Excel.Range, Cancel As Boolean)
' si clic droit fait dans la zone data de Sheet1 (feuille1)
      If Union(Target.Range("A1"), Range("data")).Address = Range("data").Address Then
            'affiche menu souris avec des options définies avec CreateShortcut
            CommandBars("MenuContextuel").ShowPopup
            Cancel = True
      End If
End Sub

'partie à placer dans un module standard 
module




Option Explicit

'VériTi Juillet 2004

Sub Creer_MenuContextuel()
' procédure qui va afficher le menu "clic droit souris"
Dim MaBarre As CommandBar
Dim MonTitre As CommandBarControl

    Set MaBarre = CommandBars.Add _
                  (Name:="MenuContextuel", Position:=msoBarPopup, Temporary:=True)

    Set MonTitre = MaBarre.Controls.Add(Type:=msoControlButton)
    With MonTitre
        .Caption = "&Format Nombre..."
        .OnAction = "AfficheFormatNombre"
        .FaceId = 1554    '  icône
    End With

    Set MonTitre = MaBarre.Controls.Add(Type:=msoControlButton)
    With MonTitre
        .Caption = "&Alignement..."
        .OnAction = "AfficheFormatAlignement"
        .FaceId = 217    '  icône
    End With

    Set MonTitre = MaBarre.Controls.Add(Type:=msoControlButton)
    With MonTitre
        .Caption = "&Police..."
        .OnAction = "AfficheFormatPolice"
        .FaceId = 291    '  icône
    End With

    Set MonTitre = MaBarre.Controls.Add(Type:=msoControlButton)
    With MonTitre
        .Caption = "&Bordures..."
        .OnAction = "AfficheFormatBordure"
        .FaceId = 149    '  icône
        .BeginGroup = True
    End With

    Set MonTitre = MaBarre.Controls.Add(Type:=msoControlButton)
    With MonTitre
        .Caption = "&Remplissage..."
        .OnAction = "AfficheFormatRemplissage"
        .FaceId = 1550    '  icône
    End With

    Set MonTitre = MaBarre.Controls.Add(Type:=msoControlButton)
    With MonTitre
        .Caption = "Pr&otection..."
        .OnAction = "AfficheFormatProtection"
        .FaceId = 2654    '  icône
    End With
End Sub

'Ici pour afficher Userform Format Nombre
Sub AfficheFormatNombre()
    Application.Dialogs(xlDialogFormatNumber).Show
End Sub

'Ici pour afficher Userform Format Nombre
Sub AfficheFormatAlignement()
    Application.Dialogs(xlDialogAlignment).Show
End Sub

'Ici pour afficher Userform Format Police
Sub AfficheFormatPolice()
    Application.Dialogs(xlDialogFormatFont).Show
End Sub

'Ici pour afficher Userform format Bordure cellules
Sub AfficheFormatBordure()
    Application.Dialogs(xlDialogBorder).Show
End Sub

'Ici pour afficher Userform Couleur de remplissage
Sub AfficheFormatRemplissage()
    Application.Dialogs(xlDialogPatterns).Show
End Sub

'Ici pour afficher Userform protection cellule
Sub AfficheFormatProtection()
    Application.Dialogs(xlDialogCellProtection).Show
End Sub

Sub Enleve_MenuContextuel()
    On Error Resume Next
    CommandBars("MenuContextuel").Delete
End Sub