Option Explicit
Private Declare Function apiFindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function apiClientToScreen Lib "user32" Alias "ClientToScreen" (ByVal hWnd As Long, lpPoint As PointAPI) As Long
Private Declare Function apiGetSystemMetrics Lib "user32" Alias "GetSystemMetrics" (ByVal nIndex&) As Long
Private Const SM_CYCAPTION = 4
Private Type PointAPI
X As Long
Y As Long
End Type
Private Menu As Office.CommandBar
Private Sub btnSalir_Click()
Unload Me
End Sub
'//mnuArchivo es el nombre de una etiqueta (Label1)
Private Sub mnuArchivo_Click()
Dim P As PointAPI, hWnd&
hWnd = apiFindWindow(vbNullString, Me.Caption)
With mnuArchivo
.SpecialEffect = fmSpecialEffectSunken
P.X = .Left
P.Y = .Top + 1 + apiGetSystemMetrics(SM_CYCAPTION)
End With
Call apiClientToScreen(hWnd, P)
Menu.ShowPopup P.X, P.Y
End Sub
Private Sub mnuArchivo_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
mnuArchivo.SpecialEffect = fmSpecialEffectRaised
End Sub
Private Sub UserForm_Initialize()
Dim Save_ As Office.CommandBarButton
Dim Open_ As Office.CommandBarButton
Set Menu = Application.CommandBars.Add("MyPopup", msoBarPopup, , True)
With Menu
.Name = "MyPopup"
.Enabled = True
End With
Set Open_ = Menu.Controls.Add(msoControlButton, 1, "8890", , True)
With Open_
.Caption = "&Abrir..."
.Enabled = True
.FaceId = 23
.OnAction = "Open_" '//Procedimiento al que llama...
.Style = msoButtonIconAndCaption
.Visible = True
End With
Set Save_ = Menu.Controls.Add(msoControlButton, 1, "8889", , True)
With Save_
.Caption = "&Guardar..."
.Enabled = True
.FaceId = 3
.OnAction = "Save_"
.Style = msoButtonIconAndCaption
.Visible = True
.BeginGroup = True
End With
End Sub
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
mnuArchivo.SpecialEffect = fmSpecialEffectFlat
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Menu.Delete
Set Menu = Nothing
Unload Me
End Sub
Saludos desde Baires, JuanC