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
|
Option Explicit
Sub PrepareMenuContextuel()
Dim CB As CommandBar, CBC As CommandBarControl
Application.OnKey "%{DOWN}", "AfficherMenuContextuel"
On Error Resume Next
Application.CommandBars("MaBarre").Delete
On Error GoTo 0
Set CB = Application.CommandBars.Add( _
Name:="MaBarre", Position:=msoBarPopup, temporary:=True)
Set CBC = CB.Controls.Add(Type:=msoControlButton, before:=1, temporary:=True)
CBC.Style = msoButtonCaption
CBC.Caption = "Option 1"
CBC.OnAction = "AuTravail"
'
Set CBC = CB.Controls.Add(Type:=msoControlButton, before:=2, temporary:=True)
CBC.Style = msoButtonCaption
CBC.Caption = "Option 2"
CBC.OnAction = "AuTravail"
Set CBC = Nothing
Set CB = Nothing
End Sub
Sub AfficherMenuContextuel()
' Afficher le menu contextuel au coin
' supérieur gauche de la cellule active
Dim CX As Variant, CY As Variant
With ActiveWindow.ActivePane
CX = .PointsToScreenPixelsX(ActiveCell.Left)
CY = .PointsToScreenPixelsY(ActiveCell.Top)
End With
'
CommandBars("MaBarre").Controls(1).Caption = _
"Coordonnées en points (" _
& ActiveCell.Left & "," & Activecell.Top & ")"
CommandBars("MaBarre").Controls(2).Caption = _
"Coordonnées en pixels (" & CX & "," & CY & ")"
'
Application.CommandBars("MaBarre").ShowPopup CX, CY
'
End Sub
Sub AuTravail()
With CommandBars("MaBarre")
MsgBox "Coordonnées effectives du Popup (" _
& .Left & "," & .Top & ")"
End With
End Sub |
Partager