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
   | Option Explicit
 
Dim X As Single
Dim Y As Single
 
 
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
        .OnAction = "Macro1"
    End With
 
    With Barre.Controls.Add(msoControlButton, 2, , , True)
        .Caption = "Menu 02"
        .FaceId = 49
        .OnAction = "Macro2"
    End With
 
 
    With Me
        X = (.Width - .InsideWidth) / 2 + 8
        Y = .Height - .InsideHeight - X + 24
    End With
End Sub
 
 
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
 
 
 
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    On Error Resume Next
    CommandBars("MenuUSF").Delete
End Sub | 
Partager