PopUpMenu

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:

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
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi,
see if this untested update to your test code does what you want:

Code:
Sub TestMacro()
Dim Ctrl As CommandBarControl


'commandbar control that called code
    Set Ctrl = Application.CommandBars.ActionControl
    
    Call Shell("""" & FilePath & """ """ & Ctrl.Caption & ".PDF" & """", vbNormalFocus)
    
End Sub

Dave
 
Upvote 0
Hi,
see if this untested update to your test code does what you want:

Code:
Sub TestMacro()
Dim Ctrl As CommandBarControl


'commandbar control that called code
    Set Ctrl = Application.CommandBars.ActionControl
    
    Call Shell("""" & FilePath & """ """ & Ctrl.Caption & ".PDF" & """", vbNormalFocus)
    
End Sub

Dave

It works!!!!
Many many thanks!!!! :pray:
 
Upvote 0

Forum statistics

Threads
1,215,586
Messages
6,125,683
Members
449,249
Latest member
ExcelMA

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top