condorelli
New Member
- Joined
- Jul 27, 2017
- Messages
- 12
Hi all!!
I need to return in a Macro the selected caption of a PopUpMenu...
In a Module:
I need to return in a Macro the selected caption of a PopUpMenu...
In a Module:
Code:
Option Explicit
Public Const Mname As String = "MyPopUpMenu"
Sub DeletePopUpMenu()
' Delete the popup menu if it already exists.
On Error Resume Next
Application.CommandBars(Mname).Delete
On Error GoTo 0
End Sub
Sub CreateDisplayPopUpMenu()
' Delete any existing popup menu.
Call DeletePopUpMenu
' Create the popup menu.
Call Custom_PopUpMenu_1
' Display the popup menu.
On Error Resume Next
Application.CommandBars(Mname).ShowPopup
On Error GoTo 0
End Sub
Sub Custom_PopUpMenu_1()
Dim MenuItem As CommandBarPopup
Dim rFind As Range
Dim lFind As Range
Dim i As Long
With Range("Piani")
Set lFind = .Find(What:=Left(ActiveCell.Offset(0, -1).Value, 2), LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
Set rFind = .Find(What:=Right(ActiveCell.Offset(0, -1).Value, 2), LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
End With
' Add the popup menu.
With Application.CommandBars.Add(Name:=Mname, Position:=msoBarPopup, _
MenuBar:=False, Temporary:=True)
' First, add buttons to the menu.
For i = -(lFind.Row - rFind.Row) To 0
With .Controls.Add(Type:=msoControlButton)
.Caption = lFind.Offset(i, 0).Value
.FaceId = 1154
.Tag = "Hello"
.OnAction = "'" & ThisWorkbook.Name & "'!" & "TestMacro"
End With
Next
End With
End Sub
Sub TestMacro()
Call Shell("""" & FilePath & """ """ & [SIZE=2][B][COLOR=#ff0000]????the selected caption????[/COLOR][/B][/SIZE] & ".PDF" & """", vbNormalFocus)
End Sub