Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Dim i%, Bar1 As CommandBar, Bar2 As CommandBar, barX As CommandBar
Set Bar1 = Application.CommandBars("Cell")
Set Bar2 = Application.CommandBars("List Range Popup")
With Bar1
.Reset
With .Controls.Add(msoControlPopup, , , 1, True)
.Caption = "Aller à l'onglet ..."
For i = 1 To ThisWorkbook.Sheets.Count
If ThisWorkbook.Sheets(i).Visible And Not ThisWorkbook.Sheets(i).Name = Sh.Name Then
With .Controls.Add(Type:=msoControlButton)
.Caption = ThisWorkbook.Sheets(i).Name
.FaceId = 350
.OnAction = ThisWorkbook.Name & "!'Thisworkbook.Select_Feuille " & Chr(34) & .Caption & Chr(34) & "'"
End With
End If
Next i
End With
.Controls(2).BeginGroup = True
End With
With Bar2
.Reset
With .Controls.Add(msoControlPopup, , , 1, True)
.Caption = "Aller à l'onglet ..."
For i = 1 To ThisWorkbook.Sheets.Count
If ThisWorkbook.Sheets(i).Visible And Not ThisWorkbook.Sheets(i).Name = Sh.Name Then
With .Controls.Add(Type:=msoControlButton)
.Caption = ThisWorkbook.Sheets(i).Name
.FaceId = 350
.OnAction = ThisWorkbook.Name & "!'Thisworkbook.Select_Feuille " & Chr(34) & .Caption & Chr(34) & "'"
End With
End If
Next i
End With
.Controls(2).BeginGroup = True
End With
Set barX = Bar1
For Each lsto In Sh.ListObjects
'on choisi quelle barre à afficher en testant le intesect sur les listbobject et la cellule active
If Not Intersect(lsto.DataBodyRange, ActiveCell) Is Nothing Then Set barX = Bar2
Next
barX.ShowPopup
MsgBox "c'est le menu " & barX.Name & " qui a été lancé"
Bar1.Reset
Bar2.Reset
Cancel = True
Set barX = Nothing
End Sub
Private Sub Select_Feuille(Nom_Feuille$)
Sheets(Nom_Feuille).Select
End Sub