Add Custom PNG Image to Excel Ribbon

Chris Macro

Well-known Member
Joined
Nov 2, 2011
Messages
1,345
Office Version
  1. 365
Platform
  1. Windows
I am attempting to create my first add-in for excel and I have all the code written, I am just trying to make it look professional. I have been using the Custom UI Editor to create my own custom ribbon. I have some icons that I have created and want to incorporate into my ribbon however when I add them they do not show up in excel. From my research the problem is that my images are .png files and it gets tricky when you want to display icons with no "backgrounds".

I know this is possible and found an article written by Greg Maxey ( Ribbon Images & Labels Part III) but his solution was too complicated for me to understand. I any does or knows how to simplify Greg Maxey's explanation I would be very grateful as there doesn't seem to be too much on this topic out there. Thanks for you time!
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Yeah, I saw that too...He is basically referencing the same code that was written by Greg Maxey. When I look into their example files it is just really overwhelming and because they are doing a bunch of other stuff, I'm not really sure what parts of the code I need and what parts of the code are irrelevant to me. Also, I believe in Ron's example the image was stored on the computer, where I would want the image stored within the file (so that users don't have to keep track of an image file on top of the excel file). Thank you for the link Rory.

I think what I am trying to look for in this thread is someone who does this often and knows exactly what you need to have to add one .png to the file.....from there I am hoping I can figure out how to incorporate multiple png images for future projects. Do you happen to do this at all Rory?
 
Last edited:
Upvote 0
Ron's example and tip explains how to load the image into the workbook and how to refer to it - which part is causing the issue?As an aside you may find that formats other than png are easier to use - I seem to recall that colour depth and/or size can cause issues with png files
 
Upvote 0
Well going through Ron's tutorial on how to use "GetImage" Images on Custom Ribbon controls, when I open his example file (CustomImage 2.xlsm) the pictures don't even show up in the ribbon. The only thing that I can tell that looks funny in his code is the following (and that is only because it is in red font)

Bad Code?

<font face=Calibri>    <SPAN style="color:#007F00">'Windows API calls into the GDI+ library</SPAN><br>    <SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Declare</SPAN> PtrSafe <SPAN style="color:#00007F">Function</SPAN> GdiplusStartup <SPAN style="color:#00007F">Lib</SPAN> "GDIPlus" (token <SPAN style="color:#00007F">As</SPAN> LongPtr, inputbuf <SPAN style="color:#00007F">As</SPAN> GdiplusStartupInput, <SPAN style="color:#00007F">Optional</SPAN> <SPAN style="color:#00007F">ByVal</SPAN> outputbuf <SPAN style="color:#00007F">As</SPAN> LongPtr = 0) <SPAN style="color:#00007F">As</SPAN> Long<br>    <SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Declare</SPAN> PtrSafe <SPAN style="color:#00007F">Function</SPAN> GdipCreateBitmapFromFile <SPAN style="color:#00007F">Lib</SPAN> "GDIPlus" (<SPAN style="color:#00007F">ByVal</SPAN> filename <SPAN style="color:#00007F">As</SPAN> LongPtr, bitmap <SPAN style="color:#00007F">As</SPAN> LongPtr) <SPAN style="color:#00007F">As</SPAN> Long<br>    <SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Declare</SPAN> PtrSafe <SPAN style="color:#00007F">Function</SPAN> GdipCreateHBITMAPFromBitmap <SPAN style="color:#00007F">Lib</SPAN> "GDIPlus" (<SPAN style="color:#00007F">ByVal</SPAN> bitmap <SPAN style="color:#00007F">As</SPAN> LongPtr, hbmReturn <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>Ptr, <SPAN style="color:#00007F">ByVal</SPAN> background <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>Ptr) <SPAN style="color:#00007F">As</SPAN> Long<br>    <SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Declare</SPAN> PtrSafe <SPAN style="color:#00007F">Function</SPAN> GdipDisposeImage <SPAN style="color:#00007F">Lib</SPAN> "GDIPlus" (<SPAN style="color:#00007F">ByVal</SPAN> image <SPAN style="color:#00007F">As</SPAN> LongPtr) <SPAN style="color:#00007F">As</SPAN> Long<br>    <SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Declare</SPAN> PtrSafe <SPAN style="color:#00007F">Sub</SPAN> GdiplusShutdown <SPAN style="color:#00007F">Lib</SPAN> "GDIPlus" (<SPAN style="color:#00007F">ByVal</SPAN> token <SPAN style="color:#00007F">As</SPAN> LongPtr)<br>    <SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Declare</SPAN> PtrSafe <SPAN style="color:#00007F">Function</SPAN> OleCreatePictureIndirect <SPAN style="color:#00007F">Lib</SPAN> "oleaut32" (PicDesc <SPAN style="color:#00007F">As</SPAN> PICTDESC, RefIID <SPAN style="color:#00007F">As</SPAN> GUID, <SPAN style="color:#00007F">ByVal</SPAN> fPictureOwnsHandle <SPAN style="color:#00007F">As</SPAN> Long, IPic <SPAN style="color:#00007F">As</SPAN> IPicture) <SPAN style="color:#00007F">As</SPAN> Long</FONT>
 
Upvote 0
I'm wondering if it is because I don't have a certain library active?
 
Upvote 0
Per the tip in the link I posted:
1: How do I use my own icons in the Ribbon

<--- ron.png


1) Download my picture ron.png on your desktop (right click on the picture and use Save Picture As)
2) Open the file "Book1.xlsm" from the first example in the Custom UI Editor.
3) Click on the Insert Icons button or use the Insert menu to insert the file ron.png.
You see it now below the custumUI file in the Custom UI Editor, maybe you must click on the +
before customUI.xml if you not see it.


Then change this
imageMso="HappyFace"


to
image="ron"


Click on the Save button in the Custom UI Editor and open the file "Book1.xlsm"
in Excel and you see my nice face on the ribbon.


imageMso = Built-in icon
image = Your own icon
 
Upvote 0

Forum statistics

Threads
1,214,629
Messages
6,120,630
Members
448,973
Latest member
ChristineC

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