How to add icon to Excel menu / toolbar

I need to add an image to a custom toolbar / menu item that is created through VBA.

For a toolbar item, I tried the 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 work. My toolbar is initialized during a workbook load event. I noticed that the image is uploaded to the toolbar button, but in a split second it disappears and only the text of the element is displayed. My image is 16x16 pixels per second.

Any help will help solve this problem.

thanks

+4
source share
2 answers

Use the MsoButtonStyle.msoButtonIcon or one of the MsoButtonStyle elements that contain the word Icon.

+1
source

In VBA, I save the icons on a sheet (oTemplate) and pass them to the buttons using:
with NewBtn
oTemplate.Shapes("picCalcOpt").CopyPicture
.PasteFace

0
source

Source: https://habr.com/ru/post/1309874/


All Articles