Public Sub Sheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean, Tabref As ListObject)
Select Case True
Case Not Application.Intersect(Target, Tabref.HeaderRowRange) Is Nothing
Case Application.Intersect(Target, Tabref.DataBodyRange) Is Nothing
Case Else
Cancel = True 'empêche l'affichage du menu d'Excel
With Application.CommandBars("Cell")
With .Controls.Add(msoControlButton, 1, , 1, True)
.FaceId = 1088: .Caption = "Supprimer la ligne de Table"
.OnAction = "'Do_Tab " & "[" & Tabref & "].listobject" & "'"
End With
With .Controls.Add(msoControlButton, 1, , 1, True)
.FaceId = 1142: .Caption = "Ajouter une ligne de Table içi"
.OnAction = "'Do_Tab " & "[" & Tabref & "].listobject" & "'"
End With
With .Controls.Add(msoControlButton, 1, , 1, True)
.FaceId = 1145: .Caption = "Ajouter une ligne en fin de Table"
.OnAction = "'Do_Tab " & "[" & Tabref & "].listobject" & "'"
.BeginGroup = True
End With
.ShowPopup
Dim Control
For Each Control In .Controls
If Not Control.BuiltIn Then Control.Delete
Next
End With
End Select
End Sub
Sub Do_Tab(Tabref As ListObject)
ActiveSheet.Unprotect
Application.EnableEvents = False
For i = Selection.Rows.Count To 1 Step -1
Frow = Selection.Rows(i).Row
Trow = Tabref.DataBodyRange.Row
Select Case CommandBars.ActionControl.FaceId
Case 1088: Tabref.HeaderRowRange.Rows(Frow - Trow + 1).Delete ' Supprimer
Case 1142: Tabref.ListRows.Add Frow - Trow + 1 ' Ajouter içi
Case 1145: Tabref.ListRows.Add ' Ajouter en fin de table
End Select
Next
Application.EnableEvents = True
ActiveSheet.Protect
End Sub