Set a CommandBar "Popup" submenu icon dynamically

downwitch picture downwitch · Jan 19, 2011 · Viewed 13.8k times · Source

I'm just trying to confirm this: In Office 2003, I want to create a custom submenu--what is known in CommandBar parlance as a popup (msoControlPopup)--at runtime, and set an image for it. With a CommandBarButton, this is very straightforward

Set btn1 = mnu.Controls.Add(msoControlButton, temporary:=True)
btn1.Caption = "Btn1"
btn1.Picture = stdole.LoadPicture("C:\temp\test.bmp")

But with a CommandBarPopup, or CommandBarControl of type msoControlPopup, it fails

Set sub1 = mnu.Controls.Add(msoControlPopup, temporary:=True)
sub1.Caption = "Sub1"
    'object doesn't support this property or method for next line
sub1.Picture = stdole.LoadPicture("C:\temp\test.bmp")

The msoControlPopup type doesn't seem to allow a .Style property either, which is how Office determines what to show--icon, text, both--on the control. I haven't found this proven yet, so am holding out a last hope that I'm doing something wrong, and there is, in fact, a way to insert an icon on a submenu at runtime.

Thanks for any light you can shed.

Answer

downwitch picture downwitch · Jan 25, 2011

Ok well more tumbleweeds. I'm pretty sure the answer to this is, it can't be done. And here's my "proof": None of the built-in submenus have icons (which I didn't realize until after I posted the above, and if you run the above code, go to Tools > Customize in the menu bar, then click on the Test menu to drop it down, and right-click on Sub1, you should see all the button and style options greyed out. Right-click on Btn1, and they're available.

Any other thoughts still welcome.