{"id":13705407,"url":"https://github.com/cavo789/excel_ribbon","last_synced_at":"2025-05-05T16:32:37.982Z","repository":{"id":101354606,"uuid":"258732052","full_name":"cavo789/excel_ribbon","owner":"cavo789","description":"Programmer's guide to creating a Ribbon for MS Excel","archived":true,"fork":false,"pushed_at":"2022-01-17T08:56:15.000Z","size":708,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-25T03:06:42.228Z","etag":null,"topics":["excel","excel-ribbon","excel-vba","tutorial"],"latest_commit_sha":null,"homepage":null,"language":"Batchfile","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cavo789.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-04-25T09:22:08.000Z","updated_at":"2024-11-15T06:06:39.000Z","dependencies_parsed_at":"2023-03-13T15:27:58.712Z","dependency_job_id":null,"html_url":"https://github.com/cavo789/excel_ribbon","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cavo789%2Fexcel_ribbon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cavo789%2Fexcel_ribbon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cavo789%2Fexcel_ribbon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cavo789%2Fexcel_ribbon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cavo789","download_url":"https://codeload.github.com/cavo789/excel_ribbon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252533997,"owners_count":21763697,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["excel","excel-ribbon","excel-vba","tutorial"],"created_at":"2024-08-02T22:00:40.289Z","updated_at":"2025-05-05T16:32:37.634Z","avatar_url":"https://github.com/cavo789.png","language":"Batchfile","funding_links":[],"categories":["Batchfile"],"sub_categories":[],"readme":"\u003c!-- This file has been generated by the concat-md.sh script. --\u003e\n\u003c!-- Don't modify this file manually (you'll loose your changes) --\u003e\n\u003c!-- but run the tool once more --\u003e\n\u003c!-- Last refresh date: Monday, January 17, 2022, 08:52:04 --\u003e\n\n# MS Office - How to create a ribbon in Excel\n\n\u003eThis documentation will explain how to add / edit a custom ribbon in an Excel file\n\n![Banner](./banner.svg)\n\n\u003c!-- table-of-contents - start --\u003e\n* [Get the editor](#get-the-editor)\n* [Add a ribbon in MS Office](#add-a-ribbon-in-ms-office)\n  * [Add a ribbon](#add-a-ribbon)\n  * [Manifest analysis](#manifest-analysis)\n    * [The root customUI node and the namespace](#the-root-customui-node-and-the-namespace)\n      * [Define the ribbon](#define-the-ribbon)\n    * [Define the tab](#define-the-tab)\n      * [Define the ribbon](#define-the-ribbon)\n    * [Add features](#add-features)\n* [Edit a ribbon](#edit-a-ribbon)\n* [List of objects](#list-of-objects)\n* [Find images](#find-images)\n* [Assign callbacks](#assign-callbacks)\n\u003c!-- table-of-contents - end --\u003e\n\n## Get the editor\n\nTo 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.*\n\nThe tool can be downloaded from [https://bettersolutions.com/vba/ribbon/custom-ui-editor-download.htm](https://bettersolutions.com/vba/ribbon/custom-ui-editor-download.htm).\n\nFor this purpose, I've taken a copy of the software, which can be downloaded [here](./files/OfficeCustomUIEditorFiles.zip)\n\n![Custom UI Editor](./010-get-editor/images/UI_Editor.png)\n\nCustomOfficeUIEditor is an external tool (outside MS Office) who 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.\n\n## Add a ribbon in MS Office\n\nThe 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\".\n\nBy default, a standard MS Office document doesn't contain any ribbon so, when you'll open such files with the CustomOfficeUIEditor tool, you'll get an empty document.\n\nHere is a very small XML for creating a ribbon with a button and an edit box:\n\n```xml\n\u003ccustomUI xmlns=\"http://schemas.microsoft.com/office/2009/07/customui\"\u003e\n    \u003cribbon\u003e\n        \u003ctabs\u003e\n             \u003ctab id=\"customTab\" insertAfterMso=\"TabView\" label=\"Tab\"\u003e\n                \u003cgroup id=\"customGroup\" label=\"Group\"\u003e\n                    \u003cbutton\n                        id=\"customButton\"\n                        label=\"Button\"\n                        imageMso=\"HappyFace\"\n                        size=\"large\"\n                        onAction=\"OnButtonClicked\" /\u003e\n                    \u003ceditBox\n                        id=\"customEditBox\"\n                        label=\"Edit Box\"\n                        onChange=\"OnEditBoxTextChanged\" /\u003e\n                \u003c/group\u003e\n            \u003c/tab\u003e\n        \u003c/tabs\u003e\n    \u003c/ribbon\u003e\n\u003c/customUI\u003e\n```\n\n### Add a ribbon\n\nOnce you've installed CustomOfficeUIEditor, just start the interface by double-clicking on the executable. You'll get a screen like this:\n\n![Custom UI Editor](./020-add-ribbon/images/UI_Editor.png)\n\nA very simplified interface where you'll click on the `File` option to open your document.\n\nOpen any existing Excel workbook (or just create an empty one for the exercice).\n\n\u003e**When using the editor, the file itself can't be opened in Excel! Imagine the following situation: the workbook is opened 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.**\n\n![An empty file is being edited](./020-add-ribbon/images/UI_Editor_Empty.png)\n\nThe first time, you'll need to add a new ribbon: click on the `Insert` menu and select `Office 2010 Custom UI Part`.\n\n![Insert](./020-add-ribbon/images/UI_Editor_Insert.png)\n\nYou'll then obtain a screen like this:\n\n![Office 2010 Custom UI Part](./020-add-ribbon/images/UI_Editor_Insert_UI14.png)\n\nWhen `customUI14.xml` is selected (like illustrated above), click in the right pane and start to code your XML content.\n\n![Manifest added](./020-add-ribbon/images/UI_Editor_Added_UI14.png)\n\nBefore saving your file, be sure to click on the `Validate` button so a check is made to verify the quality of the content.\n\nIn the example here below, you can see that an error is displayed telling that an attribute `ID` (in uppercase) has been found and that this name isn't declared. Indeed, the correct spelling is `id` (in lowercase). *XML is a case-sensitive language and is terribly strict, no syntax errors will be tolerated*\n\n![Check](./020-add-ribbon/images/UI_Editor_Check.png)\n\nWhen the ribbon is correct, save the file and open it in Excel. If everything goes fine, you'll obtain this:\n\n![Sample](./020-add-ribbon/images/UI_Editor_Sample.png)\n\n### Manifest analysis\n\nTime to understand what has happens...\n\n#### The root customUI node and the namespace\n\n```xml\n\u003ccustomUI xmlns=\"http://schemas.microsoft.com/office/2009/07/customui\"\u003e\n```\n\nThe manifest is a XML content and should be valid. You'll need to define your content into a `\u003ccustomUI\u003e` node (mandatory) and you'll need to specify the `xmlns` (for `namespace`) attribute (mandatory).\n\nThe [namespace]{#namespace} file will define what attributes exists, are mandatory or not, for each node type. The referred URL is the `Document Type Definition` (aka *DTD*).\n\nFor instance, when the user will click on the button of your ribbon, you'll wish to be able to capture the click and start a subroutine that you've code in VBA. The \"on click event\" should be defined in the `onAction` attribute as defined in the DTD. *Microsoft maintain the documentation here: [https://msdn.microsoft.com/en-us/library/dd909370(v=office.12).aspx](https://msdn.microsoft.com/en-us/library/dd909370(v=office.12).aspx).*\n\nSo, if you know that the attribute is `onAction` you can then add your own subroutine by typing something like `onAction=\"OnButtonClicked\"`.\n\nThe job of the DTD is to make sure that the syntax of your manifest is correct; therefore, the attribute `xmlns=\"http://schemas.microsoft.com/office/2009/07/customui\"` is well mandatory.\n\n##### Define the ribbon\n\nThe ribbon should define inside the `\u003cribbon\u003e` node but not immediately since a ribbon is, in fact, always defined in a tab.\n\nBelow we can see the standard ribbon of Excel and you can see a lot of tabs: `File`, `Insert`, `Page layout`, `Formulas`, `Data`, `Review`, `View`, ...\n\n![Tabs](./020-add-ribbon/images/Tabs.png)\n\nEach tab comes with features (buttons, checkboxes, ...). For the `Insert` tab, we've first a group of three buttons into a group called `Tables`:\n\n![Insert - Group Tables](./020-add-ribbon/images/Tab_Insert_Tables.png)\n\nSo, a ribbon should be:\n\n1. Defined in a tab (his own tab or an existing one)\n2. Add features in one or more groups (own groups or existing ones)\n\nBelow, our manifest now, with the definition of the ribbon. *Lines starting with a `+` are the ones we've added. The `+` sign is here only to put in evidence the lines; the sign is not valid so don't copy/paste in your ribbon.*\n\n```diff\n\u003ccustomUI xmlns=\"http://schemas.microsoft.com/office/2009/07/customui\"\u003e\n+    \u003cribbon\u003e\n+        \u003ctabs\u003e\n+             \u003ctab id=\"customTab\" insertAfterMso=\"TabView\" label=\"Tab\"\u003e\n+                \u003cgroup id=\"customGroup\" label=\"Group\"\u003e\n+                    YOUR FEATURES HERE\n+                \u003c/group\u003e\n+        \u003c/tabs\u003e\n+    \u003c/ribbon\u003e\n\u003c/customUI\u003e\n```\n\n#### Define the tab\n\nYou'll need to give an identifier to the tab (in the attribute called `id`): your own code for a new tab or the id of an existing tab.\n\nThe standard name are:\n\n* `TabHome`\n* `TabInsert`\n* `TabPageLayoutExcel`\n* `TabFormulas`\n* `TabData`\n* `TabReview`\n* `TabView`\n* `TabDeveloper`\n\nSo, if you want to add a button to the Home tab, just use `TabHome` as value for the `id`, f.i.,\n\n```xml\n\u003ccustomUI xmlns=\"http://schemas.microsoft.com/office/2009/07/customui\"\u003e\n    \u003cribbon\u003e\n        \u003ctabs\u003e\n             \u003ctab id=\"TabHome\"\u003e\n                ADD A BUTTON TO TabHome\n        \u003c/tabs\u003e\n    \u003c/ribbon\u003e\n\u003c/customUI\u003e\n```\n\nThe XML below will, in one line,\n\n1. Create a new tab since the id `customTab` is not an existing id,\n2. Put the new tab after the existing `View` tab (use `insertBeforeMso` to add the tab before),\n3. And give him `Tab` as caption.\n\n```xml\n\u003ctab id=\"customTab\" insertAfterMso=\"TabView\" label=\"Tab\"\u003e\n```\n\nHere is our added tab:\n\n![Add_new_tab](./020-add-ribbon/images/Add_new_tab.png)\n\n##### Define the ribbon\n\nInside the `\u003ctab\u003e` declaration, you need to define at least one `\u003cgroup\u003e`. And here too, you'll to define the identifier: an existing one for, f.i., adding a button in an existing group or a new one to create a new group.\n\nThe XML below will:\n\n1. Create a new group since the id is a new one (`customGroup`),\n2. And give him `Group` as name.\n\n```xml\n\u003cgroup id=\"customGroup\" label=\"Group\"\u003e\n```\n\nOur tab with his group:\n\n![Just a group defined](./020-add-ribbon/images/Group_is_required.png)\n\nAs you can see here above, just adding a group isn't enough, you'll need to define which features (buttons, checkboxes, ...) should be added in the group.\n\n#### Add features\n\nThe XML here below will add to things: a button and an edit box.\n\n*Lines starting with a `+` are the ones we've added. The `+` sign is here only to put in evidence the lines; the sign is not valid so don't copy/paste in your ribbon.*\n\n```diff\n\u003ccustomUI xmlns=\"http://schemas.microsoft.com/office/2009/07/customui\"\u003e\n    \u003cribbon\u003e\n        \u003ctabs\u003e\n             \u003ctab id=\"customTab\" insertAfterMso=\"TabView\" label=\"Tab\"\u003e\n                \u003cgroup id=\"customGroup\" label=\"Group\"\u003e\n+                    \u003cbutton\n+                        id=\"customButton\"\n+                        label=\"Button\"\n+                        imageMso=\"HappyFace\"\n+                        size=\"large\"\n+                        onAction=\"OnButtonClicked\" /\u003e\n+                    \u003ceditBox\n+                        id=\"customEditBox\"\n+                        label=\"Edit Box\"\n+                        onChange=\"OnEditBoxTextChanged\" /\u003e\n                \u003c/group\u003e\n        \u003c/tabs\u003e\n    \u003c/ribbon\u003e\n\u003c/customUI\u003e\n```\n\nThe XML below will create a button\n\n1. With an `id` initialized to `customButton`,\n2. His label (the text that is displayed under the button) set to `Button`,\n3. Use the `HappyFace` standard image (`imageMso` is, indeed, the way to reuse a standard image while `image` allows you to define yours owns),\n4. The size of the button will be `large` (a big button),\n5. The action assigned will be the VBA function called `OnButtonClicked`.\n\n```xml\n\u003cbutton\n    id=\"customButton\"\n    label=\"Button\"\n    imageMso=\"HappyFace\"\n    size=\"large\"\n    onAction=\"OnButtonClicked\" /\u003e\n```\n\nThis will result into this:\n\n![Smiley](./020-add-ribbon/images/Smiley.png)\n\n`OnButtonClicked` is the VBA callback: to make it work, add a module in your Excel file, create a subroutine like this:\n\n```vbnet\nPublic Sub OnButtonClicked\n    Msgbox \"You've clicked on the button\", vbInformation\nEnd Sub\n```\n\nAnd we can add other features, like an edit box:\n\n```xml\n\u003ceditBox\n    id=\"customEditBox\"\n    label=\"Edit Box\"\n    onChange=\"OnEditBoxTextChanged\" /\u003e\n```\n\n![Smiley_and_edit](./020-add-ribbon/images/Smiley_and_edit.png)\n\nAs you can see here above, the list of properties depends on the type: for a button, we've a `onAction` attribute while it's an `onChange` for an editBox.\n\n## Edit a ribbon\n\nThe best way to edit a ribbon is, for sure, to use CustomOfficeUIEditor but, for instance, if you don't have the tool installed on your computer but well 7-Zip, you can edit the ribbon with 7-Zip!\n\nThe MS Office file format is, in fact, an archive. Just rename the file's extension from `.xlsx` to `.zip` if you want to verify this assertion.\n\nSo, you can start the 7-Zip interface and open a .xlsx file where a ribbon has been created.\n\nYou'll see a folder called `customUI` and, there, a file called `customUI14.xml` (remember, that was the name of our inserted ribbon). By editing that .xml file within 7-Zip (a text editor will be opened), you can see the content and update it. By saving the file from within the editor, 7-Zip will compress it and add the file to the original MS Office file.\n\n![Edit the ribbon with 7-Zip](./030-edit-ribbon/images/7-zip-ribbon.png)\n\n## List of objects\n\nAs exhaustively defined in the [ribbon's namespace](#namespace), here is the list of valid objects:\n\n* `box`,\n* `button`,\n* `buttonGroup`,\n* `checkBox`,\n* `control`,\n* `comboBox`,\n* `dropDown`,\n* `dynamicMenu`,\n* `editBox`,\n* `gallery`,\n* `labelControl`,\n* `menu`,\n* `splitButton` and\n* `toggleButton`\n\n**Be careful**: XML is case sensitive, `editBox` is the only valid syntax, `editbox` or `EditBox` aren't.\n\nEach object comes with this own attributes, some are mandatory while the others are optional.\n\n## Find images\n\nBy adding a button f.i., you'll assign an image to it.\n\nYou can use a personal image like the logo of BOSA (in that case, you'll need to import the image in the CustomOfficeUIEditor application and use the `image` attribute).\n\nYou'll most probably use an existing, standard, image. This can be done by using the `imageMso` attribute and telling Office which image to use; f.i.  `AddFolderToFavorites`:\n\n![Favorites](./050-find-images/images/Favorites.png)\n\nThe manifest is this one:\n\n```xml\n\u003ccustomUI xmlns=\"http://schemas.microsoft.com/office/2009/07/customui\"\u003e\n    \u003cribbon\u003e\n        \u003ctabs\u003e\n            \u003ctab idMso=\"TabHome\" visible=\"false\" /\u003e\n             \u003ctab id=\"customTab\" insertAfterMso=\"TabView\" label=\"Tab\"\u003e\n                \u003cgroup id=\"customGroup\" label=\"Group\"\u003e\n                    \u003cbutton\n                        id=\"customButton\"\n                        label=\"Button\"\n                        imageMso=\"AddFolderToFavorites\"\n                        size=\"large\"\n                        onAction=\"OnButtonClicked\" /\u003e\n                \u003c/group\u003e\n            \u003c/tab\u003e\n        \u003c/tabs\u003e\n    \u003c/ribbon\u003e\n\u003c/customUI\u003e\n```\n\nBut ... **how to retrieve the list of images?**\n\nMicrosoft maintains Excel files with the list of existing IDs that can be used as icons in our ribbon. The \"Office 2010 Help Files: Office Fluent User Interface Control Identifiers\" can be downloaded [here](https://www.microsoft.com/en-us/download/confirmation.aspx?id=6627). You'll get a lot of Excel files, on file by application (Access, Excel, Outlook, ...).\n\nThis will give the list of existing IDs in plain text but you'll not see the associated images.\n\nYou can download all images (as PNG) for MS Office 2010 or 2013 [here](http://hintdesk.com/2011/07/22/c-print-all-ms-office-imagemso-to-files) (see links in Chapter 2 Download).\n\nAn offline version for Office 2010 is [here](./files/Office_2010_Icon_Gallery_Files.zip) and [here](./files/Office_2013_Icon_Gallery_Files.zip) for Office 2013.\n\n## Assign callbacks\n\nThis term means: which code (VBA in this case) should be fired when an event is raised.\n\nWhen the user clicks on a button of the ribbon which subroutine should be called?\n\nThe XML code below assign the `OnButtonClicked` subroutine to the `onAction` event of the button.\n\n```xml\n\u003cbutton\n    id=\"customButton\"\n    label=\"Button\"\n    imageMso=\"AddFolderToFavorites\"\n    size=\"large\"\n    onAction=\"OnButtonClicked\" /\u003e\n```\n\nSo, if we wish to catch that event, we'll need to add a public subroutine in our Excel file, that subroutine can be placed in any module, should be public and should have `OnButtonClicked` as name.\n\nBut... depending on the callbacks (click, change, toggle state, change, ...), the definition of the subroutine is not the same.\n\nFor a button, the VBA should be something like:\n\n```vbnet\nPublic Sub OnButtonClicked(control As IRibbonControl)\n    ' YOUR CODE\nEnd Sub\n```\n\nFor an edit box and the `onChange` event, the callback is different:\n\n```xml\n\u003ceditBox\n    id=\"customEditBox\"\n    label=\"Edit Box\"\n    onChange=\"OnEditBoxTextChanged\" /\u003e\n```\n\n```vbnet\nPublic Sub OnEditBoxTextChanged(control As IRibbonControl, sText As String)\n    ' YOUR CODE\nEnd Sub\n```\n\nThe declaration of callbacks can be found on the official site :\n[How can I determine the correct signatures for each callback procedure?](\nhttps://docs.microsoft.com/en-us/previous-versions/office/developer/office-2007/aa722523(v=office.12)#how-can-i-determine-the-correct-signatures-for-each-callback-procedure). Pay attention to the `Signatures` columns; you need to look for `VBA`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcavo789%2Fexcel_ribbon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcavo789%2Fexcel_ribbon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcavo789%2Fexcel_ribbon/lists"}