Example The Create CustomMenu Item Procedure

Sub CreateCustomMenuItem()

Dim cbcpop As CommandBarControl

' Check for custom menu. If it exists then exit. Set cbcpop = Application.CommandBars( "Worksheet menu bar"). FindControl(Type:=msoControlPopup, Tag:="SRXUtilsCustomMenu")

If Not cbcpop Is Nothing Then Exit Sub

' Control does not exist -- create it. Set cbcpop = Application.CommandBars( "Worksheet menu bar"). Controls.Add(Type:=msoControlPopup, Temporary:=True)

cbcpop.Caption = "Cu&stom"

' Set tag property to find it later for deletion cbcpop.Tag = "SRXUtilsCustomMenu"

' Add menu item to popup menu

With cbcpop.Controls.Add(Type:=msoControlButton, Temporary:=True) .Caption = "&ActivateSheet" .OnAction = "ActivateSheet" End With End Sub

Also place the DeleteCustomMenuItem procedure shown in Example 10-3 into basMenus: Example 10-3. The DeleteCustomMenuItem Procedure

Sub DeleteCustomMenuItem()

Dim cbc As CommandBarControl Set cbc = Application.CommandBars( "Worksheet menu bar"). _ FindControl(Type:=msoControlPopup, Tag:="SRXUtilsCustomMenu") If Not cbc Is Nothing Then cbc.Delete End Sub

0 0

Post a comment