Sharing Controls among Multiple Workbooks

When you create custom tabs, groups, and controls using the id attribute, you always get a brand new tab, group, or control created for you — even if one already exists with the same ID or label. This is usually beneficial, because it prevents multiple add-ins accidentally changing each other's items. Occasionally, though, you may want to share those items among many add-ins or workbooks. For example, you might have an add-in that creates a basic tab, group, and menu structure, and many individual workbooks that should add items to that structure. This is achieved by using the idQ attribute to provide qualified IDs—IDs associated with a specific namespace. The namespace is provided within the customUl element and just needs to be a unique string. It is typically given an alias (Q in this case) to make the XML easier to read:

<customUI xmlns=" 6/01/customui" xmlns:Q="Excel 2007 VBA Prog Ref">

Any elements you want to share between workbooks are then defined using the idQ attribute and including the namespace alias within the ID:



<tab idQ=

: "Q:


1 label="Shared Tab">




label="Group Not Shared">

Any workbooks using the same namespace string to qualify controls with the same ID will share those controls rather than getting their own copies. In this example, any workbooks that included a namespace of xmls:Q="Excel 2 007 VBA Prog Ref" and a qualified tab ID of idQ="Q:rxShared" would all use the same tab for their controls. However, because you've used an unqualified ID for the group, that would not be shared between the workbooks. The ability to use qualified IDs in this way applies to all the container-type controls, so an add-in could create a complex menu structure using qualified IDs for all the tabs, groups, and menus, and individual workbooks could add their customizations to the shared menus.

0 0

Post a comment