How to Add Custom Ribbon Using XML in Excel

Get FREE Advanced Excel Exercises with Solutions!

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.


Download Practice Workbook

You can download the workbook to practice yourself.


Step by Step Procedures to Add Custom Ribbon Using XML in Excel

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 by Step Procedures to Add Custom Ribbon Using XML in Excel


Step 1: Create Excel Workbook

In the first step, we will create an xlsm Excel file using the given Excel file.

Create Excel Workbook to Add Custom Ribbon Using XML in Excel

  • 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 >> click on Visual Basic.

Insert VBA Code to Add Custom Ribbon Using XML in Excel

  • Now, the Microsoft Visual Basic for Application box will open.
  • Then, click on Insert >> select Module.

Opening Microsoft Visual Basic for Application Box to Add Custom Ribbon Using XML in Excel

  • 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: VBA Code to Convert XML to Excel (Apply with Quick Steps)


Step 3: Download Office RibbonX Editor

Now, we will download the Office RibbonX Editor to add custom ribbon 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”.

Download Office RibbonX Editor to Add Custom Ribbon Using XML in Excel

  • 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.

Opening Office RibbonX Editor Setup Box to Add Custom Ribbon Using XML in Excel

  • 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.

Read More: How to Convert XML to XLSX Without Opening File


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.

Open Excel File in Office RibbonX Editor to Add Custom Ribbon Using XML in Excel

  • Then, click on Open.

  • Now, the Open OOXML Document box will appear.
  • After that, select the xlsm file and click on Open.

Opening Open OOXML Document Box to Add Custom Ribbon Using XML in Excel

Read More: How to Open XML File in Excel for Income Tax (2 Easy Ways)


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.

Insert XML in Office RibbonX Editor and Validate the Code to Add Custom Ribbon Using XML in Excel

  • 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, selected Home Tab as idMso.
  • After that, we added a customGroup labelled as Open MsgBox and customButton1 labelled as Click Here.
  • Next, set the MacroZ macro as onAction and HappyFace as imageMso.
  • Then, click on the Validation button to check the code.

Clicking on Validation Button to Add Custom Ribbon Using XML in Excel

  • Now, if no error is found inthe 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.

Read More: How to Extract Data from XML File to Excel (2 Easy Ways)


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.

Excel Custom Ribbon XML

  • 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.

Open Excel Workbook to Check Custom Ribbon to Add 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.

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. And visit ExcelDemy for many more articles like this. Thank you!


Related Articles

Arin Islam

Arin Islam

Hello, I'm Arin. I graduated from Khulna University of Engineering and Technology (KUET) from the Department of Civil Engineering. I am passionate about learning new things and increasing my data analysis knowledge as well as critical thinking. Currently, I am working and doing research on Microsoft Excel and here I will be posting articles related to it.

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo