Create Custom Pop-up Menu w/Icon in VBA

JarekM

Board Regular
Joined
Nov 13, 2018
Messages
86
Hi,
I want to be able to put my own custom icons in Excel. The code below works nicely, but instead of FaceID, I want to replace it with my own icon or image.
Can someone help me with this problem.

Code:
Public The_Menu As CommandBar
Function CreateSubMenu() As CommandBar

Const pop_up_menu_name = "Pop-up Menu"

Dim the_command_bar As CommandBar
Dim the_command_bar_control As CommandBarControl

    'Deletes any CommandBars that may be present
    For Each menu_item In CommandBars
        If menu_item.Name = pop_up_menu_name Then
          CommandBars(pop_up_menu_name).Delete
        End If
    Next

    ''Add our popup menu to the CommandBars collection
    Set the_command_bar = CommandBars.Add(Name:=pop_up_menu_name, Position:=msoBarPopup, MenuBar:=False, Temporary:=False)
       
        '*****Menu Options*****
        Set the_command_bar_control = the_command_bar.Controls.Add
         the_command_bar_control.Caption = "Add"
         the_command_bar_control.OnAction = "Add"
         the_command_bar_control.FaceId = 3
        Set the_command_bar_control = the_command_bar.Controls.Add
         the_command_bar_control.Caption = "Edit"
         the_command_bar_control.OnAction = "Add"
        Set the_command_bar_control = the_command_bar.Controls.Add
         the_command_bar_control.Caption = "Add"
         the_command_bar_control.OnAction = "Add"
        Set the_command_bar_control = the_command_bar.Controls.Add
         the_command_bar_control.Caption = "Add"
         the_command_bar_control.OnAction = "Add"
          
    Set CreateSubMenu = the_command_bar

End Function

Code:
Private Sub Label61_Click()
    Set The_Menu = CreateSubMenu
    The_Menu.ShowPopup
End Sub

Thank you.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Thank you for your quick response.
The link that you sent helped me out a lot.

Also, would you be kind enough to tell me how I can add a line separator to the pop-up menu.

Thanks again for the help.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,215
Members
448,554
Latest member
Gleisner2

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