Reputation: 11
I’ve been updating a Word report template we use at work and wanted to embed some macros into it. Having downloaded the Custom UI Editor for Word, I used the “Insert/Sample XML/Custom Tab” function to add a custom tab (imaginatively called “Macros”) with three new buttons on it; I then edited the XML to assign a different formatting macro to each button. This works just fine and I am very happy with it.
However I now want to add a fourth button (and corresponding macro) to my new tab. Having opened up the document again in the Custom UI Editor, I’m finding that when I try to add a fourth button to the existing new tab, I instead get another whole new tab (“Macros 2”, if you like) containing the original three new buttons, and the fourth one. So I have two new tabs with the same name, one with three buttons and one with four.
What have I done wrong? How can I improve my way of working / use different XML to avoid this problem?
XML code used for the original three buttons (all created at once)
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<ribbon startFromScratch="false">
<tabs>
<tab id="customTab" label="Macros">
<group id="customGroup" label="Formatting Macros">
<button id="customButton" label="Extract acronyms" imageMso="TextEffectShadowGallery" size="large" onAction="ExtractACRONYMSToNewDocument2" />
<button id="customButton2" label="Format sentence spacing" imageMso="TextEffectTracking" size="large" onAction="FormatSentenceSpacing" />
<button id="customButton3" label="Format current table" imageMso="TableSelectCell" size="large" onAction="FormatCurrentTableInHouseStyle" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
Code I’m using to try to add a fourth button to the ribbon (but it creates a whole new tab instead of just adding a button to the existing new ribbon)
<button id="customButton4" label="Format current table" imageMso="UseThisImage" size="large" onAction="FormatTableMacro" />
I’ve tried
Upvotes: 1
Views: 742
Reputation: 25693
XML has very strict rules about what can be where: Hierarchy is very important.
In the case of Ribbon XML everything must be nested within the <customUI>
and <ribbon>
tag pairs (and in that order). So if you try to put something else "outside" of those, the Custom UI Editor is trying to save you from the error you'd get if you'd use that XML and is making a new tab for you. (Cool, I didn't know it would do that!)
A button has a very low hierarchical status - so it must be nested (at the very least) within <tabs>
and <tab>
. Since you're grouping your buttons, it also must be inside the <group>
pair of tags.
It's fine for you to edit the XML the Custom UI Editor shows you. Follow these steps to create your fourth button:
</group>
tag.Upvotes: 2