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.
Watch the Video
More Excel VBA Tutorials
- Format specific words in a cell using Excel VBA
- Using the OnTime method in VBA
- Excel macro to email a workbook as an attachment