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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| Option Explicit
Dim Xa As Single
Dim Ya As Single
'Création de la barre d'outils lors du lancement du UserForm
Private Sub UserForm_Initialize()
Dim Barre As CommandBar
Set Barre = CommandBars.Add("MenuUSF", msoBarPopup, False, True)
With Barre.Controls.Add(msoControlButton, 1, , , True)
.Caption = "Menu 01"
.FaceId = 50
'La procédure va appeler une macro nommée "Macro1", lorsque vous cliquerez
'sur le bouton.
.OnAction = "Macro1"
End With
With Barre.Controls.Add(msoControlButton, 2, , , True)
.Caption = "Menu 02"
.FaceId = 49
'La procédure va appeler une macro nommée "Macro2", lorsque vous cliquerez
'sur le bouton.
.OnAction = "Macro2"
End With
With Me
Xa = (.Width - .InsideWidth) / 2 + 8
Ya = .Height - .InsideHeight - Xa + 24
End With
End Sub
Private Sub CommandButton1_MouseMove(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, _
ByVal Y As Single)
Dim PosX As Single, PosY As Single
'Button correspond au clic de la souris
'1= clic gauche
'2= clic droit
If Button = 2 Then
PosX = (Me.Left + Xa + CommandButton1.Left) * 4 / 3
PosY = (Me.Top + Ya + CommandButton1.Top) * 4 / 3
Application.CommandBars("MenuUSF").ShowPopup PosX, PosY
End If
End Sub
'Supprime la barre d'outils lors de la fermeture du UserForm
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
On Error Resume Next
CommandBars("MenuUSF").Delete
End Sub |
Partager