Add Custom PNG Image to Excel Ribbon

Chris Macro

Well-known Member
Joined
Nov 2, 2011
Messages
1,341
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!
 

Some videos you may like

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,121
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
Have you reviewed this?
 

Chris Macro

Well-known Member
Joined
Nov 2, 2011
Messages
1,341
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:

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,121
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
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
 

Chris Macro

Well-known Member
Joined
Nov 2, 2011
Messages
1,341
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>
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,121
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
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
 

Watch MrExcel Video

Forum statistics

Threads
1,102,287
Messages
5,485,906
Members
407,523
Latest member
Talicius

This Week's Hot Topics

Top