Looking for ways to add custom ribbon using XML in Excel? Then, this is the right place for you. Here, you will find a step-by-step way to add a custom ribbon using XML in Excel.
How to Add Custom Ribbon Using XML in Excel: Step by Step Procedures
Suppose we have a dataset containing some students’ Student ID, Name, and Marks. Now, we will show you how you can open a MsgBox by adding a custom ribbon in Excel using XML in this Excel file.
Follow the steps given below to do it on your own.
Step 1: Create Excel Workbook
In the first step, we will create an xlsm Excel file using the given Excel file.
- Firstly, open the Excel file and click on File.
- Then, click on Save a Copy.
- After that, give a name to your file.
- Next, select Excel Macro-Enabled Workbook (*.xlsm) file option from the drop-down.
- Finally, click on the Save button to save the file as an xlsm file.
Step 2: Insert VBA Code
Next, we will insert a VBA code that will open a MsgBox. To do that, go through the steps shown below.
- In the beginning, go to the Developer tab (enable the Developer tab on your ribbon) >> click on Visual Basic.
- Now, the Microsoft Visual Basic for Application box will open.
- Then, click on Insert >> select Module.
- Next, write the following code in your Module.
Sub MacroZ(control As IRibbonControl)
MsgBox "Here, You will see the Marksheet of the Students."
End Sub
Code Breakdown
- Firstly, we created a Sub Procedure named MacroZ and set the control as IRibbonControl.
- Then, we inserted a MsgBox with text.
- After that, click on the Save button to save the code.
- Finally, close the Excel file.
Read More: How to Use Excel VBA to Customize Ribbon
Step 3: Download Office RibbonX Editor
Now, we will download the Office RibbonX Editor to add custom ribbons using XML in Excel. This Editor was found on this site. Then, follow the steps given below.
- Firstly, select the link shown below and Right-click on it.
- Secondly, click on Search Google for “github.com”.
- Then, in that link, you find the Installer file like the file shown below.
- Now, download the file and open it.
- Next, the Office RibbonX Editor Setup box will open.
- Firstly, select I accept the agreement.
- After that, click on Next.
- Here, select the file Destination Location and click on Next.
- Further, click on Next.
- Again, click on Next.
- Then, click on Install.
- Finally, click on Finish.
- Thus, you can download the Office RibbonX Editor.
Step 4: Open Excel File in Office RibbonX Editor
In the fourth step, we will open our xlsm file in the Office RibbonX Editor to add a custom ribbon using XML in Excel.
- To start with, open the Office RibbonX Editor.
- Then, click on Open.
- Now, the Open OOXML Document box will appear.
- After that, select the xlsm file and click on Open.
Step 5: Insert XML in Office RibbonX Editor and Validate the Code
Next, we will insert the XML code in the Office RibbonX Editor. Go through the steps shown below to do this for your own dataset.
- Firstly, select the Excel file.
- Then, click on Insert.
- Next, select Office 2007 Custom UI Part.
- After that, insert the following XML code in the Office RibbonX Editor.
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon>
<tabs>
<tab idMso="TabHome" >
<group id="customGroup1" label="My Group" insertAfterMso="GroupEditingExcel">
<button id="customButton1" label="Click Me" size="large"
onAction="Macro1" imageMso="HappyFace" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
Code Breakdown
- Firstly, we opened the customUI file.
- Then, select Home Tab as idMso.
- After that, we added a customGroup labeled as Open MsgBox and customButton1 labeled as Click Here.
- Next, set the MacroZ macro as onAction and HappyFace as imageMso.
- Then, click on the Validation button to check the code.
- Now, if no error is found in the code a MsgBox like below will open.
- Further, click on OK.
- Next, to save the code, click on File >> click on Save As.
- After that, the Save OOXML box will open.
- Further, give the file with your desired name and click on Save.
Step 6: Open Excel Workbook to Check Custom Ribbon
In the final step, we will open the xlsm Excel file again to check if a custom ribbon has been added or not.
- In the beginning, open the xlsm Excel file.
- Here, you will notice that a new button such as Click Here has been added under the Open MsgBox group.
- Then, click on the Click Here button.
- Finally, a MsgBox will open that you created using the VBA code.
- That’s it. This is how you can add a custom ribbon using XML in Excel.
Things to Remember
- Remember to close the Excel file before opening the Office RibbonX Editor.
- You can execute any code written in your module using this editor but remember to change the macro name in onAction in the given XML code.
- Check your XML code using Validation.
Download Practice Workbook
You can download the workbook to practice yourself.
Conclusion
So, in this article, we have shown you a step-by-step way to add a custom ribbon using XML in Excel. I hope you found this article interesting and helpful. If something seems difficult to understand, please leave a comment. Additionally, please let us know if there are any more alternatives that we may have missed. Thank you!