I am finding myself repeating a lot of XML when writing RibbonXML UIs.
Take, for example, the following contextMenu
<contextMenu idMso="ContextMenuObjectsGroup">
<!-- Lots of XML describing the items -->
</contextMenu>
Now, I also want the same items to appear in the ContextMenuShape
menu, so I find myself duplicating the above:
<contextMenu idMso="ContextMenuShape">
<!-- Lots of XML describing the items -->
</contextMenu>
This is exacerbated by the fact that all contained controls need new Id
s - and the code behind needs to be adapted to respond to these new controls.
Question:
Is there a way to de-duplicate this code and simply reference control groups (which are implemented once) from within, e.g.,
contextMenu
s,ribbon
s and so on?
Edit 1: Further use Cases
I developed a couple of custom user functions which can be applied to shapes, tables, charts and so on. I am currently including these tools in the tab set TabSetDrawingTools
. However, I also need them included in the respective tabs for tables and charts.
From what I see right now, there are only two options:
As above, completely copy & paste all the code - which is contrary to any sort of best practices
Somehow implement my "own" ribbon XML tags. I then read my own XML, look for tags such as
<customControlGroup id="myId" />
and then, from that, generate the final Ribbon XML programmatically and pass it to Office. That said, this sounds like a lot of hassle to achieve something seemingly so simple.
Edit 2: Use of <control />
Not Supported
Ribbon XML offers the <control />
tag, allowing you to duplicate/clone built-in controls. However, as per the documentation (and having tried it), it does not work with custom controls and control groups (e.g. by referencing their id
or idQ
).