Develop Office Business Applications using Visual Studio
Last month I posted this article that described how to prevent your add-in from creating duplicate menu items in Word. If you have been experimenting with customization contexts, you might have several menu items that appear when you right click a document. The article that I posted shows how to prevent this from happening for your users, but what about removing the items that appear in your instance of Word – the one that you use for testing?
To clear those off, just add a bit of code to the startup event handler of any old Word add-in. Set the customization context to each possible culprit (template, document, attached template etc.) and then call the Reset method. Be sure to save the template or document after words.
Note - I wouldn’t recommend that you put this code into an add-in that you send out to users as this code will remove all customizations in each context (Even ones that your add-in has not created!). However, it is a cool way to clear up left over menu items from the instance of Word that you use for testing.
private void ResetShortcutMenu() { myApplication.CustomizationContext = myApplication.ActiveDocument; myApplication.CommandBars["Text"].Reset(); myApplication.ActiveDocument.Save(); myApplication.CustomizationContext = myApplication.ActiveDocument.get_AttachedTemplate(); myApplication.CommandBars["Text"].Reset(); ((Word.Template)myApplication.ActiveDocument.get_AttachedTemplate()).Save(); myApplication.CustomizationContext = customTemplate; myApplication.CommandBars["Text"].Reset(); customTemplate.Save(); myApplication.CustomizationContext = myApplication.NormalTemplate; myApplication.CommandBars["Text"].Reset(); myApplication.NormalTemplate.Save(); }
PingBack from http://microsoft-sharepoint.simplynetdev.com/clearing-off-custom-menu-items-in-word-norm-estabrook/