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
| Function menu(boutons, bt, Optional mode As String = "")
Dim i As Long, Barre As CommandBar, pop, e As Long, decal As Long, XX, YY As Long, oP As Double
On Error GoTo suite
delmenu
suite:
With ActiveWindow.ActivePane: oP = (.PointsToScreenPixelsY(33) - .PointsToScreenPixelsY(0)) / 33: End With
Set Barre = CommandBars.Add("MenuUSF", msoBarPopup, False, True)
For i = 0 To UBound(boutons)
If IsArray(boutons(i)) Then
Set pop = Barre.Controls.Add(msoControlPopup, 1, , , True): pop.Caption = boutons(i)(UBound(boutons(i)))
pop.Caption = boutons(i)(UBound(boutons(i)))
For e = 0 To UBound(boutons(i)) - 1
With pop.Controls.Add(msoControlButton, 1, , , True)
.Caption = Split(boutons(i)(e), ":")(0)
.FaceId = Split(boutons(i)(e), ":")(1)
.Enabled = Val(Split(boutons(i)(e), ":")(2))
.OnAction = Split(boutons(i)(e), ":")(3)
End With
Next
Else
With Barre.Controls.Add(msoControlButton, 1, , , True)
.Caption = Split(boutons(i), ":")(0)
.FaceId = Split(boutons(i), ":")(1)
.Enabled = Val(Split(boutons(i), ":")(2))
.OnAction = Split(boutons(i), ":")(3)
If UBound(Split(boutons(i), ":")) > 3 Then .BeginGroup = True
End With
End If
Next
DoEvents
If mode = "usf" Then
XX = bt.Left * oP 'position left du label cliqué en pixel par raport au point 0 du insidewidth de l'userform
YY = (bt.Top + bt.Height) * oP ' position top du label cliqué en pixel en dessous le bouton par rapport au point 0 du insideheight de l'userform
topPlus = (bt.Parent.Height - bt.Parent.InsideHeight) * oP ' epaisseur de la caption du userform en pixel
ep_cadre = bt.Parent.Width - bt.Parent.InsideWidth 'epaiseur du cadre (donne 3 en general)
Barre.ShowPopup (UserForm1.Left * oP) + ep_cadre + XX, UserForm1.Top * oP + topPlus - ep_cadre + YY ' affichage de la popup au cordonnéees calculées
Else
Barre.ShowPopup
End If
End Function
Function delmenu()
On Error Resume Next
CommandBars("MenuUSF").Delete
End Function |