Computer >> Computer tutorials >  >> Software >> Office

How to Add Custom Ribbon Using XML in Excel

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.

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.

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

  • Firstly, open the Excel file and click on File.

How to Add Custom Ribbon Using XML in Excel

  • Then, click on Save a Copy.

How to Add Custom Ribbon Using XML in Excel

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

How to Add Custom Ribbon Using XML in Excel

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.

How to Add Custom Ribbon Using XML in Excel

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

How 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

How to Add Custom Ribbon Using XML in Excel

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.

How to Add Custom Ribbon Using XML in Excel

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

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

How to Add Custom Ribbon Using XML in Excel

  • Next, the Office RibbonX Editor Setup box will open.
  • Firstly, select I accept the agreement.
  • After that, click on Next.

How to Add Custom Ribbon Using XML in Excel

  • Here, select the file Destination Location and click on Next.

How to Add Custom Ribbon Using XML in Excel

  • Further, click on Next.

How to Add Custom Ribbon Using XML in Excel

  • Again, click on Next.

How to Add Custom Ribbon Using XML in Excel

  • Then, click on Install.

How to Add Custom Ribbon Using XML in Excel

  • Finally, click on Finish.
  • Thus, you can download the Office RibbonX Editor.

How to Add Custom Ribbon Using XML in Excel

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.

How to Add Custom Ribbon Using XML in Excel

  • Then, click on Open.

How to Add Custom Ribbon Using XML in Excel

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

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

How to Add Custom Ribbon Using XML in Excel

  • Next, select Office 2007 Custom UI Part.

How to Add Custom Ribbon Using XML in Excel

  • After that, insert the following XML code in the Office RibbonX Editor.
<customUI xmlns="https://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>

How to Add Custom Ribbon Using XML in Excel

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.

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

How to Add Custom Ribbon Using XML in Excel

  • Next, to save the code, click on File >> click on Save As.

How to Add Custom Ribbon Using XML in Excel

  • After that, the Save OOXML box will open.
  • Further, give the file with your desired name and click on Save.

How to Add Custom Ribbon Using XML in Excel

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.

How to Add Custom Ribbon Using XML in Excel

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

How 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

  • How to Convert XML to Columns In Excel (4 Suitable Ways)
  • How to Convert Large XML to Excel (2 Effective Ways)