Assign non-Face Id icon to a commandbar button?

Frenchi

New Member
Joined
Oct 15, 2002
Messages
18
I'm creating an XLA addin. This addin creates a commandbar, button and assign the appropriate macro. I really would like to use by own Icon and NOT a FaceID. How do I accoplish this task? Using Excel 97.
(I did a search on this BB and could not find antyhing to solve this riddle.)
Thanks
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Well, what I've used is to put the bitmap, or whatever, somewhere in the sheet, then, copy it, and use the .PasteFace method of your commandbarbutton.
 
Upvote 0
I think its bitmap. Even better if you create/copy the picture in a small format (I think its 16 x 16 pixels), that way, you shouldn't have resizing problems when you paste it.
 
Upvote 0
Ok I tried. Unfortunately is an Add-in it did not work. I was unable to select the image via VB in the XLA. I have no problem when it is an XLS file.
Thanks
 
Upvote 0
Hi Frenchi,

See if the following routines are of any help in understanding how to add a custom picture to your menu items.

<pre>'===============================================================
Sub AddMenu()
' This procedure adds a custom menu item
Dim ctlCBarControl As CommandBarControl
Dim cbpPopup As CommandBarPopup
Dim cmdButton As CommandBarButton

' create a popup control on the Tools menu
For Each ctlCBarControl In Application.CommandBars _
("Worksheet Menu Bar").Controls("Tools").Controls
If ctlCBarControl.Caption = "MyCustomMenu" Then _
ctlCBarControl.Delete
'already exists so delete first
Next

' Custom menu item added
Set cbpPopup = Application.CommandBars("Worksheet Menu Bar"). _
Controls("Tools").Controls.Add _
(msoControlPopup, , , 3, False)
'3=position in menu, False=Permanent
cbpPopup.Caption = "MyCustomMenu"
cbpPopup.Visible = True

' add item to the submenu
Set cmdButton = cbpPopup.Controls.Add(Type:=msoControlButton)
cmdButton.Visible = True
cmdButton.Style = msoButtonIconAndCaption 'icon and caption
cmdButton.Caption = "MySubMenu"
cmdButton.OnAction = "MyMacro" 'action to perform
Sheet1.Shapes("MyPicture").Copy ' copy the custom icon
cmdButton.PasteFace ' paste the custom icon

Set ctlCBarControl = Nothing
Set cbpPopup = Nothing
Set cmdButton = Nothing
'Release memory from Object variables

End Sub
'===============================================================
'

'===============================================================
Private Sub RemoveMenu()

' If the Custom Menu exists, delete it.
On Error Resume Next
Application.CommandBars("Worksheet Menu Bar") _
.Controls("Tools").Controls("MyCustomMenu").Delete

End Sub
'===============================================================
'</pre>

HTH

PS. I find Icon editors useful for creating the
custom button faces as you can specify the 16X16 size.

PPS. In the above examples, your custom picture
is stored on sheet1.
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,334
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top