Custom menu disappears

F

Fredrik E. Nilsen

Ok, probably a stupid question but:

I'm creating a custom menu with buttons to apply custom user defined
charts:

Dim myMenu As Object
Set myMenu = CommandBars("Worksheet menu
bar").Controls.Add(Type:=msoControlPopup)

With myMenu
.Caption = "User defined charts"
. . .
End With

The problem is: this menu disappears when a chart is selected. I can
change it to "Chart menu bar" but then it disappears when no chart is
selected.

What do I have to put there to make the menu visible all the time?
 
B

Bob Phillips

Add to both Worksheet menu Bar and Chart Menu Bar commandbars.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
B

Bob Phillips

Repeat the code that you have changing Worksheet Menu bar to Chart Menu Bar
in the second instance of that code.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
F

Fredrik E. Nilsen

Repeat the code that you have changing Worksheet Menu bar to Chart Menu Bar
in the second instance of that code.

Thanks, I figured out I could do it like that. But it seems strange to
me if there is no method to achieve this in one statement?
 
J

Jon Peltier

You need to add the menu to two menu bars, so it takes two statements, or a
loop.

Dim myMenu As Object
dim vMenuBars as variant
dim iMenu as integer

vMenuBars = Array("Worksheet Menu Bar", "Chart Menu Bar")
For iMenu = 0 to 1
Set myMenu =
CommandBars(vMenuBar(iMenu)).Controls.Add(Type:=msoControlPopup)
With myMenu
.Caption = "User defined charts"
' etc.
End With
Next

- Jon
 
B

Bob Phillips

Why would it? They are separate commandbars applicable to different
circumstances, so it seems reasonable to me that you program both.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
J

Jon Peltier

or...

Dim cBar as commandbar
dim myMenu as CommandBarControl
For Each cBar in Application.Commandbars
If cBar.Type = msoBarTypeMenuBar then
set myMenu = cBar.Controls.Add(Type:=msoControlPopup)
' etc.
End If
Next

- Jon
 
F

Fredrik E. Nilsen

or...

Dim cBar as commandbar
dim myMenu as CommandBarControl
For Each cBar in Application.Commandbars
If cBar.Type = msoBarTypeMenuBar then
set myMenu = cBar.Controls.Add(Type:=msoControlPopup)
' etc.
End If
Next

As always: thank you very much for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top