Link to home
Start Free TrialLog in
Avatar of Jamie Garroch (MVP)
Jamie Garroch (MVP)Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Is it possible to use the same ribbon XML fluent UI control ID in an Office VBA add-in using idQ?

I develop VBA add-in for Office apps and utilise the customUI XML framework to specify the UI.

I have often wondered if it's possible to avoid the situation where I need the same control to appear in multiple parts of the UI without having to create multiple unique control IDs and hence manage that in the callback code. For example, let's say I need a button in a right-click content menu "Show Object Info" and I need that feature to appear for multiple different selection types. Can I use qualified IDs (idQ) to achieve this somehow. Basically, how can I have duplicate IDs in the same XML definition whose callbacks fire the same code in a VBA add-in?

Example working snippet using the unique IDs "Test1" and "Test2":

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
	<contextMenus>
		<contextMenu idMso="ContextMenuPicture">
			<button id="Test1" label="Show Object Info" onAction="OnAction"/>
		</contextMenu>
		<contextMenu idMso="ContextMenuTable">
			<button id="Test2" label="Show Object Info" onAction="OnAction"/>
		</contextMenu>
	</contextMenus>
</customUI>

Open in new window


Example snippet using a single duplicate non-unique qualified IDs "Test" which presents the control in the UI but the callbacks don't work (no code is run):

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" xmlns:yp="http://youpresent.co.uk">
	<contextMenus>
		<contextMenu idMso="ContextMenuPicture">
			<button idQ="yp:Test" label="Show Object Info" onAction="OnAction"/>
		</contextMenu>
		<contextMenu idMso="ContextMenuTable">
			<button idQ="yp:Test" label="Show Object Info" onAction="OnAction"/>
		</contextMenu>
	</contextMenus>
</customUI>

Open in new window

This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.