Custom Button Images

P

Pflugs

I know how to create custom toolbars and menus, but I want to design my own
button images (say in Paint or Photoshop) and attach those to my custom
commands. I found this site:

http://www.vertex42.com/ExcelTips/excel-toolbar-buttons.html

that shows how to download GIF files and paste the image to a button or menu
item. Is this possible programmatically? Or can I set a button image from a
file when I create the menu from my VBA code?

Thanks,
Pflugs
 
G

Gary''s Student

If you create the button with the Controls toolbox rather than forms, then
right-click the button and select Properties. Go down to picture, select it
and pick a picture from the resulting dialog box
 
P

Pflugs

That's interesting and useful, but I really want to change the image of a
toolbar or menu button, not a forms or controls button. Do you know of any
way to do this using VBA?

Thanks,
Pflugs
 
G

Gary''s Student

I see. Since it is easy to change the toolbar button images manually, it can
be done with VBA. The Macro Recorder won't help. I'll investgate and update
this tomorrow.
 
P

Pflugs

I have found a way. After a few more hours of digging, I found this example
in the help menu:

Sub ChangeButtonImage()
Dim picPicture As IPictureDisp
Dim picMask As IPictureDisp

Set picPicture = stdole.StdFunctions.LoadPicture( _
"c:\images\picture.bmp")
Set picMask = stdole.StdFunctions.LoadPicture( _
"c:\images\mask.bmp")

'Reference the first button on the first command bar
'using a With...End With block.
With Application.CommandBars.FindControl(msoControlButton)
'Change the button image.
.Picture = picPicture

'Use the second image to define the area of the
'button that should be transparent.
.Mask = picMask
End With
End Sub

Thus, to complete my company add-in, I will program code to create a custom
toolbar and menu, and then the code will load the pictures from a company
shared folder. I think that will work nicely.

Thanks for helping me!
Pflugs
 

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