Sub W_Brc(ByVal Target As Range, Cancel As Boolean) ' Worksheet_BeforeRightClick
Dim Sh As Worksheet
Dim Control As Object
Dim Rbar As CommandBar
Const Cb = "RightClick"
Cancel = True
On Error Resume Next: CommandBars(Cb).Delete: On Error GoTo 0
Set Rbar = CommandBars.Add(Cb, msoBarPopup, , True)
With Rbar
With .Controls.Add(msoControlPopup, , , .Controls.Count + 1, True)
.Caption = "Activer feuille"
For Each Sh In ThisWorkbook.Worksheets
Select Case True
Case Sh.Name = ActiveSheet.Name
Case Sh.Type <> xlWorksheet
Case Else
With .Controls.Add(msoControlButton, , , , True)
.Caption = Sh.Name
.FaceId = 1154
.OnAction = "Show_Tab"
End With
End Select
Next
End With
For Each Sh In ThisWorkbook.Worksheets
Select Case True
Case Sh.Name = ActiveSheet.Name
Case Sh.Type <> xlWorksheet
Case Else
With .Controls.Add(msoControlButton, , , , True)
.Caption = Sh.Name
.FaceId = 634
.OnAction = "Show_Tab"
End With
End Select
Next
Copy_Controls Rbar, IIf(ActiveCell.ListObject Is Nothing, "Cell", "List Range Popup")
.ShowPopup
.Delete
End With
End Sub
Sub Copy_Controls(To_Bar As CommandBar, From_Bar As String, Optional BlankLine As Boolean = False)
Dim CBar As CommandBarControl
On Error Resume Next
With To_Bar
' Ligne de séparation
If BlankLine Then .Controls.Add(msoControlButton, , , .Controls.Count + 1, True).Caption = ""
' Controls habituels du click droit
With .Controls.Add(msoControlPopup, , , .Controls.Count + 1, True)
' .BeginGroup = True
.Caption = "Autres Choix"
For Each CBar In CommandBars(From_Bar).Controls
.Controls.Add CBar.Type, CBar.ID, , , True
Next
End With
End With
End Sub
Sub Show_Tab()
Dim Target As String
With CommandBars.ActionControl
Select Case .Type
Case msoControlButton: Target = .Caption
Case msoControlDropdown: Target = .Text
Case Else: Exit Sub
End Select
With Worksheets(Target)
.Visible = True
.Activate
End With
End With
End Sub