CommandBar Popup: How to recreate the submenu

J

Jim Gordon MVP

Here's the setup:

I created a toolbar called "BWTools" and I want to add the functionality
that comes with a built-in toolbar command along with that command's
pop-up submenu.

Both of the following syntax statements successfully add the desired
control to the existing "BWTools" toolbar:

Set MyBar = CommandBars("BWTools").Controls.Add(Id:=742)
or
Application.CommandBars("BWTools").Controls.Add Type:=msoControlPopup,
Id:=742, Before:=2

At this point I have the desired control and an empty stub that's
waiting for the submenu items.

The following syntax adds submenu items successfully (and even adds
pictures to the submenu items which I thought was impossible)

With MyBar
.Controls.Add Type:=msoControlButton, Id:=2, Before:=1
.Controls.Add Type:=msoControlButton, Id:=3, Before:=2
End With

So far so good. But I want to use the commands that would normally be on
this control in the pop-up submenu.

How do I figure out the ID numbers of the items that are on control 742
when you drag it to a toolbar? It is this command: (Toolbars > Customize
Menus and Toolbars > Commands > Grayscale settings)

-Jim
 
S

Steve Rindsberg

Here's the setup:

I created a toolbar called "BWTools" and I want to add the functionality
that comes with a built-in toolbar command along with that command's
pop-up submenu.

Both of the following syntax statements successfully add the desired
control to the existing "BWTools" toolbar:

Set MyBar = CommandBars("BWTools").Controls.Add(Id:=742)
or
Application.CommandBars("BWTools").Controls.Add Type:=msoControlPopup,
Id:=742, Before:=2

At this point I have the desired control and an empty stub that's
waiting for the submenu items.

The following syntax adds submenu items successfully (and even adds
pictures to the submenu items which I thought was impossible)

With MyBar
.Controls.Add Type:=msoControlButton, Id:=2, Before:=1
.Controls.Add Type:=msoControlButton, Id:=3, Before:=2
End With

So far so good. But I want to use the commands that would normally be on
this control in the pop-up submenu.

How do I figure out the ID numbers of the items that are on control 742
when you drag it to a toolbar? It is this command: (Toolbars > Customize
Menus and Toolbars > Commands > Grayscale settings)

-Jim

Simplest way I know is like this:

Manually using the customize feature
- create a new commandbar named Test
- add the b/w options button to it

Then run this:

Sub TellJim()
Dim x As Long
Dim oCtl As CommandBarControl

' Get a reference to the first control on the Test toolbar
Set oCtl = Application.CommandBars("Test").Controls(1)

' The control is a popup so it has its own .Controls collection
' That's what you're after:
For x = 1 To oCtl.Controls.Count
Debug.Print oCtl.Controls(x).Caption & vbTab & oCtl.Controls(x).Id
Next
End Sub


================================================
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
 
J

Jim Gordon MVP

You're awesome, Steve!

Here's the result:
&Automatic 2733
&Grayscale 2739
&Light Grayscale 2742
&Inverse Grayscale 2740
Gra&y with White Fill 2738
Blac&k with Grayscale Fill 2735
Bla&ck with White Fill 2736
&Black 2734
&White 2741
&Don't Show 2737

-Jim
 
S

Steve Rindsberg

You're awesome, Steve!

Herself says you spelled that wrong. She says it's "awe-ful"
<g>

I can't swear to the IDs but the results look pretty much like what I got here
when I tried it.

You can also extend the same idea and iterate through the whole
Application.CommandBars collection to get *everything* but this seems a lot
easier for a quickie.
Here's the result:
&Automatic 2733
&Grayscale 2739
&Light Grayscale 2742
&Inverse Grayscale 2740
Gra&y with White Fill 2738
Blac&k with Grayscale Fill 2735
Bla&ck with White Fill 2736
&Black 2734
&White 2741
&Don't Show 2737

-Jim

================================================
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
 
J

Jim Gordon MVP

Well it worked just fine and my commandbar is working exactly the way I
hoped it would on Macintosh PowerPoint 98, 2001, X, and 2004.

You would think the macro would work for Windows PowerPoint 2003, but
alas, I will have to write special code for that puppy.
 
S

Steve Rindsberg

Well it worked just fine and my commandbar is working exactly the way I
hoped it would on Macintosh PowerPoint 98, 2001, X, and 2004.

You would think the macro would work for Windows PowerPoint 2003, but
alas, I will have to write special code for that puppy.

What've you run into there?

And you do know that you can simply set the B/W values you want directly,
right? It's one of the various read/write properties of a shape.


================================================
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
 

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