Can we place an Icon and a Caption on a CommandButton ?

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
9,806
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have a commandbutton on a userform and I want place on it an icon and a descriptive text below it.

Based on a couple of testings, I managed to add an icon to the commandbutton without obscuring the caption text BUT it only works if the icon is very small (16x16) which results in a slightly blurry icon due to the icon small size ... Adding a bigger sharper icon doesn't seem to work as it completly obscures the caption text.

Any ideas\workarounds ?

Regards.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
what if you superimposed a transparent label over the commandbutton and transfer the event back to the commandbutton code, that way the icon can be bigger and the text can be fitted to a light area... just thinking out loud here :)
 
Upvote 0
what if you superimposed a transparent label over the commandbutton and transfer the event back to the commandbutton code, that way the icon can be bigger and the text can be fitted to a light area... just thinking out loud here :)
Thanks diddi.

That sounds like a good workaround, but might be a little tricky to implement for multiple buttons added at runtime.

This is for a little game involving the creation of images and buttons on the fly.
 
Upvote 0
"but might be a little tricky to implement for multiple buttons added at runtime."
i guess as a beginner you might find that :biggrin:
 
Upvote 0
Thanks.

I saw that video already while searching the net before posting my question here, but I was looking at something that would allow for larger icons/bitmaps and that would felxibly allow for assigning the icon + text programmatically at runtime.
 
Upvote 0
The following will create a button on the active sheet and assign text :

VBA Code:
Sub butonekle()
ActiveSheet.Buttons.Add(11.5, 3.25, 80.75, 26.25).Select
Selection.OnAction = "formac"
Selection.Characters.Text = "Form"
Sayfa1.Buttons.Copy
For i = 2 To Sheets.Count
    Sheets(i).Activate
    Range("a1").Select
    ActiveSheet.Paste
    Range("A1").Select
Next
End Sub

You should be able to add the button image in the code as well.

Don't know if this will assist any : Dynamic macro button label
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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