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
| Option Explicit
Dim X As Single
Dim Y 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
X = (.Width - .InsideWidth) / 2 + 8
Y = .Height - .InsideHeight - X + 24
End With
End Sub
'Affiche la barre d'outils lorsque vous cliquez sur le label.
Private Sub Label1_Click()
Dim PosX As Single, PosY As Single
PosX = (Me.Left + X + Label1.Left) * 4 / 3
PosY = (Me.Top + Y + Label1.Top) * 4 / 3
Application.CommandBars("MenuUSF").ShowPopup PosX, PosY
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