Clearing Off Custom Menu Items in Word (Norm Estabrook)

Published 14 April 09 11:37 AM

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();
}

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Clearing Off Custom Menu Items in Word (Norm Estabrook) | Microsoft Share Point said on April 14, 2009 4:11 PM:

PingBack from http://microsoft-sharepoint.simplynetdev.com/clearing-off-custom-menu-items-in-word-norm-estabrook/

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

About VSTO Team

This login represents the Visual Studio Tools for Office team. Many members of the team us this account for publishing technical blog posts.

This Blog

Syndication

Page view tracker