VBA menus - How do I make menu visible when a chart is selected?

bstuchin

New Member
Joined
Sep 27, 2008
Messages
8
Hello,
I'm trying to write a simple menu generator script that creates a two-list menu called "Valuation" that has two menu lists "Format Data Table" and "Format Chart." So far, the macro works fine, but the only problem is that the menu disappears when a chart is actually selected. I'd like the menu to stay visible when a chart is selected so that a user can run the macro on the selected chart. Can someone please help me with this? I have a comment in the code for where the "Format Chart" item should be visible.

Thanks in advance!
Blake

Code:
Sub Auto_open()
' Sub CreateMenu()
' creates a new menu
' can also be used to create commandbarbuttons
' may be automatically executed from an Auto_Open macro or a Workbook_Open eventmacro
Dim cbMenu As CommandBarControl ', cbSubMenu As CommandBarControl
  RemoveMenu ' delete the menu if it already exists
    ' create a new menu on an existing commandbar (the next 6 lines)
    Set cbMenu = Application.CommandBars(1).Controls.Add(msoControlPopup, , , , True)
    With cbMenu
        .Caption = "Va&luation"
        .Tag = "MyTag"
        .BeginGroup = False
        .Enabled = True
    End With
    If cbMenu Is Nothing Then Exit Sub ' didn't find the menu...

    ' add menuitem to menu
    With cbMenu.Controls.Add(msoControlButton, 1, , , True)
        .Caption = "Format Data Table"
        .OnAction = ThisWorkbook.Name & "!checkForm1"
    End With
    
        With cbMenu.Controls.Add(msoControlButton, 1, , , True)
        .Caption = "Format Chart"
    ' I would like this to be visible if a chart is selected
        .OnAction = ThisWorkbook.Name & "!checkForm2"
    End With
    
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
In 2003 or earlier, put the commands of interest in the appropriate place in the 'Worksheet Menu Bar' commandbar and the 'Chart Menu Bar' commandbar -- rather than identifying a commandbar by number as you did with commandbars(1)
 
Upvote 0

Forum statistics

Threads
1,216,326
Messages
6,130,057
Members
449,555
Latest member
maXam

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