How to get the path selected by user??

ogo

Board Regular
Joined
Mar 15, 2011
Messages
105
Hi ,

I have the following code for a pop up.

Code:
Option Explicit
Public Const Mname As String = "MyPopUpMenu"
Sub DeletePopUpMenu()
'Delete PopUp menu if it exist
On Error Resume Next
Application.CommandBars(Mname).Delete
On Error GoTo 0
End Sub
Code:
'RUN THIS
Sub CreateDisplayPopUpMenu()
    'Delete PopUp menu if it exist
    Call DeletePopUpMenu
    'Create the PopUpmenu
    Call Custom_PopUpMenu_1
    'Show the PopUp menu
    On Error Resume Next
    Application.CommandBars(Mname).ShowPopup
    On Error GoTo 0
End Sub
Code:
Sub Custom_PopUpMenu_1()
    Dim MenuItem As CommandBarPopup
    'Add PopUp menu
    With Application.CommandBars.Add(Name:=Mname, Position:=msoBarPopup, _
                                     MenuBar:=False, Temporary:=True)
       ' Add menu with two buttons
        Set MenuItem = .Controls.Add(Type:=msoControlPopup)
        With MenuItem
            .Caption = "My Special Menu"
            With .Controls.Add(Type:=msoControlButton)
                .Caption = "Button 1 in menu"
                .FaceId = 71
                .OnAction = "'" & ThisWorkbook.Name & "'!" & "TestMacro"
            End With
            With .Controls.Add(Type:=msoControlButton)
                .Caption = "Button 2 in menu"
                .FaceId = 72
                .OnAction = "'" & ThisWorkbook.Name & "'!" & "TestMacro"
            End With
        End With
    End With
End Sub
 
Sub TestMacro()
    MsgBox "Hi"
End Sub

How do i get the option selected by the user??
For example, If user selects My Special Menu --> Button 1 then i sholud store this path to a variable..

Please help
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Thanks for replying Andrew, if i do like as you said it would give me the last caption selected, i require the complete patH.
Is there any work around to this??
 
Upvote 0
What do you mean by "the complete path"?

I needed to store the data like
menu-> submenu1->submenu2->Option1

I sorted out a way.
I am using four different status values to call TestMacro example: TestMacro(1,1,1,1)
and from there i added code below.
Code:
Sub TestMacro(val1,val2,val3,val4)
 
     If val4 <> 0 Then
        MsgBox "You selected " & Application.CommandBars(Mname).Controls(val1).Caption & _
        "->" & Application.CommandBars(Mname).Controls(val1).Controls(val2).Caption & _
        "->" & Application.CommandBars(Mname).Controls(val1).Controls(val2).Controls(val3).Caption & _
        "->" & Application.CommandBars(Mname).Controls(val1).Controls(val2).Controls(val3).Controls(val4).Caption
    'If 3rd menu is not there, pass the 3rd argument as 0
    ElseIf (val3 <> 0) Then
        MsgBox "You selected " & Application.CommandBars(Mname).Controls(val1).Caption & _
        "->" & Application.CommandBars(Mname).Controls(val1).Controls(val2).Caption & _
        "->" & Application.CommandBars(Mname).Controls(val1).Controls(val2).Controls(val3).Caption
    ElseIf (val2 <> 0) Then
        MsgBox "You selected " & Application.CommandBars(Mname).Controls(val1).Caption & _
        "->" & Application.CommandBars(Mname).Controls(val1).Controls(val2).Caption
    End If

Thank you once again for replying..
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,558
Members
452,928
Latest member
101blockchains

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