Reputation: 41
I need to add a image to a custom toolbar/menu item which is create through VBA.
For a toolbar item, I tried following code
Set NewBtn = TBar.Controls.Add(Type:=msoControlButton)
With NewBtn
.Picture = LoadPicture("mypic.bmp")
.OnAction = "'MyFunction""" & para1 & """'" //VBA Function
'.Caption = "MyFunction"
.TooltipText = "MyFunction"
.Style = msoButtonCaption
End With
In the above code LoadPicture() does not seem to be working. My toolbar is initializing at the workbook load up event. I noticed that the image is loading to the toolbar button, but in a fraction of second it disappears and only item text is displayed. My image is 16x16 pixel bmp one.
Any help appreciate to get around this problem
Thank you
Upvotes: 4
Views: 5863
Reputation: 23550
In VBA I store the icons on a worksheet (oTemplate) and transfer them to the buttons using:
with NewBtn
oTemplate.Shapes("picCalcOpt").CopyPicture
.PasteFace
Upvotes: 0
Reputation: 21684
Use MsoButtonStyle.msoButtonIcon
or one of the MsoButtonStyle
members that contain the word Icon.
Upvotes: 1