问题
So ive got two different COM addins, one for word 2k3 and one for 2k7. word 2k3 works like a charm everytime, no issues etc...but now when I open word 2k7, the buttons from 2k3 appear in my 2k7 ribbon. This still happens even after I disable my addin or clean my project...i've tried everything, including deleting all dlls for my 2k3 addin but the problem still persists...
any suggestions on what the problem is?
cheers
回答1:
If you make a point of configuring those buttons in a template OTHER than normal.dot, they will automatically "go away" when you install.
It's generally considered bad practice to make changes to Normal.dot, but many people don't realize that unless you set the "CustomizationContext" property in word before creating you're own buttons and toolbars, that's precisely what you're doing, modifying normal.dot, and those changes WILL persist after you've uninstalled your addin.
回答2:
You must "manually" remove the button as part of your uninstall process. This is the code I use:
public static void removeWordToolbarButton(
Microsoft.Office.Interop.Word.Application word )
{
var commandBar = word.CommandBars["Tools"];
var btn = commandBar.FindControl(
Microsoft.Office.Core.MsoControlType.msoControlButton,
System.Reflection.Missing.Value,
"name_of_the_button",
System.Reflection.Missing.Value,
System.Reflection.Missing.Value ) as Microsoft.Office.Core.CommandBarButton;
if ( btn != null )
{
btn.Delete( -1 );
Marshal.ReleaseComObject( btn );
}
Marshal.ReleaseComObject( commandBar );
}
回答3:
I suspect that the problem relies in normal.dot template. Try to save normal template after removing buttons, commandbars etc using:
wordApplication.NormalTemplate.Save();
来源:https://stackoverflow.com/questions/5451013/com-add-in-not-going-away-in-word-2007