# VBA & MS Office automation A series of 10 article(s), in reading order. # MS Office - How to create a ribbon in Excel > Step-by-step guide on creating a custom VBA Excel Ribbon. Use XML and VBA to add your own tabs, groups, buttons, and powerful features to your Excel workbooks. --- ![MS Office - How to create a ribbon in Excel](/img/v2/ribbon.webp) **TL;DR** This article walks through building a custom Excel ribbon using the free `CustomOfficeUIEditor` tool and hand-written XML (the `customUI14.xml` manifest): defining tabs, groups, and controls like buttons and edit boxes, wiring their `onAction`/`onChange` events to VBA callback subroutines, and finding standard `imageMso` icon IDs to use on buttons. In this post, we'll learn how to create a ribbon (i.e. a toolbar) in Microsoft Excel. We'll create our custom ribbon for an Excel file, save the ribbon in the file so our users will have a nice and intuitive interface to work with our worksheet. *A ribbon is only useful if its buttons do something interesting. For a concrete example, [MS Excel - Connect to a SQL Server database, run a query and get the results](/blog/vba-excel-sql-server-part-2) gives you the VBA behind a "Refresh data" button.* ## What we're going to build Here is the end result: our own tab, in Excel, with a button and an input field. ![Smiley\_and\_edit](./images/Smiley_and_edit.webp) The button is wired to a VBA subroutine, so clicking it runs your code: ![Button clicked](./images/Button_clicked.webp) The whole thing is about fifteen lines of XML stored inside the workbook. Anyone opening your `.xlsm` file gets the ribbon; there's nothing to install on their machine. ## Why it works * An `.xlsx` / `.xlsm` file is not a binary blob: it's a ZIP archive with files and folders inside. You can open one with 7-Zip and look around. * Adding a ribbon means adding one file to that archive: a manifest called `customUI14.xml`, which describes the tabs, groups and controls in XML. * When MS Office opens the workbook, it reads that manifest, draws the ribbon and, on each click, calls the VBA subroutine named in the control's `onAction` attribute. Your macro and your interface are thus stored in the same single file. ## Download the editor for free To be able to "easily" *(in a not WYSIWYG interface)* create a ribbon in MS Office, I'm using a very old tool called `CustomOfficeUIEditor`. *Until now, I've not found any other free tool for doing this.* The tool can be downloaded from . `CustomOfficeUIEditor` is an external tool (outside MS Office) which can open an Office file and add the needed files to create a ribbon. It's possible to do this without an editor, for instance by using a software like 7-Zip since a `.xlsx` / `.xlsm` file is an archive with files and folders. For this exercise; please extract all files and folders to your `C:\tmp\ribbon` folder (create it). ## Create an empty file As a support for this blog post, please create a new, empty, file in Excel called `Ribbon.xlsm` in your `C:\tmp\ribbon` folder (or elsewhere). ![Excel Ribbon.xlsm](./images/Excel_empty_file.webp) > **Just creates an empty file:** > > Right now, we don't need to do anything other than File - New - Save as - FileType - Excel Macro-Enabled Workbook. ## Add a ribbon in MS Office The `CustomOfficeUIEditor` tool isn't a user-friendly tool: you'll need to type yourself the XML of the ribbon. That XML is also called *the manifest file*. By default, a standard MS Office document doesn't contain any ribbon so, when you open such files with the `CustomOfficeUIEditor` tool, you'll get an empty document. *Outlook is the exception: there, no XML is needed at all since the built-in `Customize the Ribbon` dialog can host a macro button, as done in [Microsoft Outlook - VBA - Save emails as PDF](/blog/outlook-vba-pdf).* Please start `CustomOfficeUIEditor` and open your `Ribbon.xlsm` file: ![UI - Open Ribbon.xlsm](./images/UI_open.webp) > **Make sure to close it first if still open in Excel:** > > When using the editor, the file itself can't be opened in Excel! Imagine the following situation: the workbook is open both in the editor and in Excel. You make a lot of changes in Excel, switch to the editor and change the manifest. By saving the file in the editor, you'll lose every change made in Excel so... be careful. The first time, you'll need to add a new ribbon: click on the `Insert` menu and select `Office 2010 Custom UI Part`. ![Insert](./images/UI_Editor_Insert.webp) You'll then obtain a screen like this: ![Office 2010 Custom UI Part](./images/UI_Editor_Insert_UI14.webp) When `customUI14.xml` is selected (like illustrated above), click somewhere in the right pane and start to code your XML content. Now, in the right pane, just copy/paste the XML source below: **customUI14.xml** ```xml