Chewyhairball
Active Member
- Joined
- Nov 30, 2017
- Messages
- 312
- Office Version
- 365
- Platform
- Windows
Hi Folks,
I have a code that gives me a nice popup menu( in my example there are 3 options to choose from).
It works really well but i was wondering if a sub menu was possible. Like selecting the first item from the menu which would then open up with further options to choose from.
thanks for any help with this.
I have a code that gives me a nice popup menu( in my example there are 3 options to choose from).
It works really well but i was wondering if a sub menu was possible. Like selecting the first item from the menu which would then open up with further options to choose from.
thanks for any help with this.
VBA Code:
Option Explicit
Public Const Mname As String = "MyPopUpMenu"
Sub CreatePopUpMenu()
' Delete any existing popup menu.
Call DeletePopUpMenu
' Create the popup menu.
Call Custom_PopUpMenu_Actions
' Display the popup menu.
On Error Resume Next
Application.CommandBars(Mname).ShowPopup
On Error GoTo 0
End Sub
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 Custom_PopUpMenu_Actions()
Dim MenuItem As CommandBarPopup
' Add the popup menu.
With Application.CommandBars.Add(Name:=Mname, Position:=msoBarPopup, _
MenuBar:=False, Temporary:=True)
' First, add two buttons to the menu.
With .Controls.Add(Type:=msoControlButton)
.Caption = "Add Comments"
.FaceId = 67
.OnAction = "'" & ThisWorkbook.Name & "'!" & "macro1"
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "Add Comments"
.FaceId = 329
.OnAction = "'" & ThisWorkbook.Name & "'!" & "macro2"
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "Add Comments"
.FaceId = 225
.OnAction = "'" & ThisWorkbook.Name & "'!" & "macro3"
End With
End With
End Sub