Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need custom icon when creating Custom CommandBar in Excel code

Status
Not open for further replies.

SBendBuckeye

Programmer
May 22, 2002
2,166
US
I have a custom command bar which I create in an Excel file's form open code. If I create it manually using Tools, Customize I can copy in my own gif file as the button face. I copy it to the clipboard and then paste it into my new custom commandbar.

How do I do the same thing when creating it via VBA code? Thanks in advance for any ideas and/or suggestions!

Have a great day!

j2consulting@yahoo.com
 
Try the following:

Dim picMask As IPictureDisp
Dim picbutton As IPictureDisp
Dim MyControl(1) As CommandBarButton

Set MyControl(1) = Application.CommandBars(myBarName).Controls(1)
MyControl(1).Style = msoButtonIconAndCaption
MyControl(1).Parameter = i
MyControl(1).FaceId = 0
Set picMask = stdole.StdFunctions.LoadPicture(<path to Mask.bmp>)
MyControl(1).Caption = "Your Caption Here"
MyControl(1).TooltipText = "Your Tooltip Here"
MyControl(1).OnAction = "Name of Subroutine to execute when user presses button"
Set picbutton = stdole.StdFunctions.LoadPicture(<path to yourpic.bmp>)
MyControl(1).Picture = picbutton
MyControl(1).Mask = picMask

Notes:
MyControl doesn't have to be an array.
Mask.bmp is a bmp file that is all black.
I don't know if a .gif file will work. If not, convert it to a .bmp.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top