I've built an Add-In for Word and would now like to add an option to call a function from it when a user highlights a word and right clicks on it. I've found documentation here on how to modify the manifest.xml file but it doesn't seem to show a full example of how to add to the contextual menu, only how to add buttons and drop down menus.
The documentation also points me to a github page show examples but again lacks one for contextual menus. It also points to this video which seems to show what I want at about 1:20 but also doesn't show how to implement it.
So far I have this (added below the <FunctionFile>
):
<ExtensionPoint xsi:type="ContextMenu">
<OfficeMenu id="ContextMenuText">
<Control xsi:type="Menu" id="TestMenu">
<Label resid="ContextMenuLabel" />
<Supertip>
<Title resid="ContextualMenuTitle" />
<Description resid="ContextualMenuTitleDesc" />
</Supertip>
</Control>
</OfficeMenu>
</ExtensionPoint>
When I try and validate the manifest file with this tool it tells me that I'm missing an Icon
element, but I don't need an image for a context menu?
Is what I'm trying to do possible and if so could someone point me to an example?
Edit:
I've updated my code to reflect what @Mavi Domates wrote
<ExtensionPoint xsi:type="ContextMenu">
<OfficeMenu id="ContextMenuText">
<Control xsi:type="Button" id="openSearchButton">
<Label resid="openSearchButtonLabel" />
<Supertip>
<Title resid="openSearchButtonTitle" />
<Description resid="openSearchButtonDescription" />
</Supertip>
<Icon>
<bt:Image size="16" resid="Contoso.tpicon_16x16" />
<bt:Image size="32" resid="Contoso.tpicon_32x32" />
<bt:Image size="80" resid="Contoso.tpicon_80x80" />
</Icon>
<Action xsi:type="ExecuteFunction">
<FunctionName>getData</FunctionName>
</Action>
</Control>
</OfficeMenu>
</ExtensionPoint>
When I add this code (right below the default <ExtensionPoint xsi:type="PrimaryCommandSurface">
My add-in no longer shows up in the "My Add-ins" menu. I downloaded Microsoft's manifest validator and it tells me my manifest is fine.
I've narrowed it down to the Control
node causing the problem. If I just add:
<ExtensionPoint xsi:type="ContextMenu">
<OfficeMenu id="ContextMenuText">
</OfficeMenu>
</ExtensionPoint>
my add-in still shows in the menu. I've also added the relevant strings in my resources under <bt:ShortStrings>
:
<bt:String id="openSearchButtonLabel" DefaultValue="Check it out!" />
<bt:String id="openSearchButtonTitle" DefaultValue="Hover over me" />
<bt:String id="openSearchButtonDescription" DefaultValue="For more info go here" />
My code seems to be exactly the same as the documentation. I'm not sure where to go from here. I'm on a mac if that changes things.