问题描述
我想知道我可以编程方式加载和卸载一个VSTO加载在Word中。我使用的是Word 2007和VS2010用C#。
I'd like to know how I can programatically load and unload a VSTO add-in in Word. I'm using Word 2007 and VS2010 with C#.
我想我可能有一些运气使用Microsoft.Office.Interop.Word.COMAddins和.Addins性能,但.Addins属性给出一个空列表和COMAddins是不透明的COM对象的集合。
I thought I might have some luck with using the Microsoft.Office.Interop.Word.COMAddins and .Addins properties, but the .Addins property gives an empty list and COMAddins is a collection of opaque COM objects.
这是的建议制定功能区菜单中看不见的,但其实我是想卸载加载干脆。
An alternative question suggests making the ribbon menu invisible, but I actually want to unload the add-in altogether.
推荐答案
我有类似的要求,一点作弊做到了这一点。
I had similar requirement and achieved it by little cheat.
我有一个名为AddinLauncher(无带)的插件,这将查找用户类型并启动或关闭其他插件。
I had a addin called AddinLauncher (with no ribbons) which will look for the user type and launch or closes the other addin.
这代码AddinLauncher期间调用加载项启动的事件。
This code was called during AddinLauncher Addin Startup event.
foreach (COMAddIn addin in Globals.ThisAddin.Application.COMAddins)
{
if (**specify your own condition**)
{
addin.Connect = true;
}
}
需要在部署中的以下更改
The following changes are required in your deployment
Loadbehaviour为AddinLaucher插件是3和其他所有加载项均为0
更多Loadbehaviour的
The Loadbehaviour for AddinLaucher addin is 3 and all the other addins are 0.More about Loadbehaviour here
这篇关于如何加载/卸载Word加载编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!