In this blog post, we look at how you can use your own icon or image for the button of your macro on the Ribbon.
This could be an image that you have created, or one that you downloaded from a website.
By using our own icons we can create customised workbooks and not be constrained by the standard Microsoft icon set provided.
In this example, I have a macro that exports all the worksheets of a workbook to PDF, and I want to assign it to the icon shown below. This icon was downloaded from flaticon.com, a fantastic resource for icons that you can use for your macros.
Download the Custom UI Editor for Office
To insert our icon into a Ribbon of an Excel file we need the Custom UI Editor for Office. This is free to download and if you do not have it already you can download it here – Custom UI Editor for Office.
Adding your Own Icon to the Ribbon for your Macro
Open the Custom UI Editor and open the Excel workbook where you would like to add your icon.
You may see some XML code appear as soon as you open the file, but you will probably need to insert some sample XML code to get started.
You can do this by clicking Insert, Sample XML and then Custom Tab.
This code can now be edited to work for you. Change the label for the tab, group and then button to what you want to use.
Then enter the name of the image you want to use for the image argument. In the example below my image is saved as analytics-72. Shortly we will insert this into the Excel workbook.
Finally enter the name of your macro for the onAction argument. My macro is called ExportAsPDF.
You can copy and paste the relevant lines of code to easily add more buttons, groups or tabs.
Insert your Image to the Workbook
With the code now set to add your icon to the Ribbon and run your macro, we need to insert the image into the workbook so that it is there to be used.
Click the Insert menu and then Icons. Browse and select your icon and it will be added to the file. You can see it on the left. Click the + sign next to the workbook name to expand the list of all added icons.
Ken Witchel says
Thank you very much for this tutorial. I have been wanting to do something like this for a while. Your example showed how to add a custom ribbon to a workbook. Could I also create an add-in and use the Custom UI editor to add my own icons? Would I create a new ribbon for PERSONAL.XLSB?
computergaga says
You can create icons on a Ribbon of a workbook and save it as an add-in for distribution. I have not tried creating one in the PERSONAL.XLSB before but cannot see why this would not work also.
Ken Witchel says
Thank you for the prompt reply. I have two more questions:
1. To access Microsoft’s icons, would I leave imageMSO as is?
2. If I add a ribbon to a workbook, if I then copy the workbook, would the ribbon also be copied. If this is the case, then in certain situations, would this negate the need for a separate add-in?
computergaga says
1. Yes imageMSO is for the Microsoft icons.
2. Yes, I believe if you copy the workbook then the Ribbon would be contained with it. I guess this does reduce the advantages of an add-in. An add-in would remain a far more efficient way of distributing macros, or in this case a Ribbon tab though. Especially in a business environment.
Gayle says
Hello I love these nice clear instructions so thank you! I want to add a custom image to macros I have written and I want these to appear on the ribbon every time I open a new workbook. I currently have quite a few macros that I have displaying on a custom tab in the ribbon but the standard microsoft icon images don’t match the macro functions well at all 🙁 How would I go about achieving this?
computergaga says
You may be able to follow the steps and add the icon to the Personal.xlsb workbook making it available to new workbooks. I havn’t tried this, the blog post demonstrates adding an icon to a specific workbook, but I’m confident it would work.