How to add icon to command bar menu item

B

Bob Smedley

I am creating a new command on Word's main Menu Bar with a bunch of sub menu
items below that. I want the sub menu items to be of the "Icon and Caption"
type. I have ICO files for each of the sub menu items. I cannot seem to find
out how to get the image from the ICO file to the sub menu item. Help would
be appreciated.

Here is my code so far...

Set MenuObject = Application.CommandBars("Menu Bar"). _
Controls.Add(Type:=msoControlPopup, _
Temporary:=True)
MenuObject.Caption = "My Menu Bar Item"


Set MenuItem = MenuObject.Controls.Add(Type:=msoControlButton)
MenuItem.OnAction = "MyMacroName"
MenuItem.Caption = "This will eventually do something"
MenuItem.Style = msoButtonIconAndCaption

I know the PasteFace method is available but it depends upon the image
already being in the clipboard. Plus I would like the images to be part of
the DOT file rather than being files on the hard drive. I thought maybe
using an imagelist or image control on a hidden form but the problem is how
to get the image on to the clipboard.

Suggestions?

thanks
 
C

Cindy M -WordMVP-

Hi Bob,

You could, possibly, store them as AutoText entries within the template. Then
insert them into the document (or a new document) so that you can copy them.

The other approach that's been used is a toolbar, especially for this purpose,
that's kept hidden at all other times.

However, if you're creating a template, why not simply put all the sub-menus
into the template, and just set their Visible property to true when you want
the user to have access to them?

You do realize you can make template-specific changes to CommandBars in Word?
Just select that file from the "look in" list. Or, if you're making the
changes programmatically, make sure to set Application.CustomizationContext
before calling any CommandBar stuff.
I am creating a new command on Word's main Menu Bar with a bunch of sub menu
items below that. I want the sub menu items to be of the "Icon and Caption"
type. I have ICO files for each of the sub menu items. I cannot seem to find
out how to get the image from the ICO file to the sub menu item. Help would
be appreciated.

Here is my code so far...

Set MenuObject = Application.CommandBars("Menu Bar"). _
Controls.Add(Type:=msoControlPopup, _
Temporary:=True)
MenuObject.Caption = "My Menu Bar Item"


Set MenuItem = MenuObject.Controls.Add(Type:=msoControlButton)
MenuItem.OnAction = "MyMacroName"
MenuItem.Caption = "This will eventually do something"
MenuItem.Style = msoButtonIconAndCaption

I know the PasteFace method is available but it depends upon the image
already being in the clipboard. Plus I would like the images to be part of
the DOT file rather than being files on the hard drive. I thought maybe
using an imagelist or image control on a hidden form but the problem is how
to get the image on to the clipboard.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

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