remove an add-in from MS Word
来源:互联网 发布:水是什么意思网络用语 编辑:程序博客网 时间:2024/05/08 23:14
I need to programmatically remove an add-in from MS Word. I have deleted the registry entry corresponding to it, and the button is now disabled (nothing happens when you click it) and the add-in no longer appears on the list of COM Add-ins.
The button, however, remains in the Add-ins ribbon menu. How can I remove that programmatically?
========================================================================
CoInitialize(NULL);
CLSID clsid;
IDispatch *pWApp, *pCommandBars, *pCommandBar, *pCommandBarControls, *pCommandBarControl;
VARIANT v;
HRESULT hr;
hr = CLSIDFromProgID(L"Word.Application", &clsid);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (void **)&pWApp);
if (SUCCEEDED(hr))
{
VariantInit(&v);
hr = OLEMethod(DISPATCH_PROPERTYGET, &v, pWApp, L"Commandbars", 0);
pCommandBars = v.pdispVal;
VariantInit(&v);
hr = OLEMethod(DISPATCH_PROPERTYGET, &v, pCommandBars, L"Count", 0);
INT NumCommBars = v.intVal;
for (INT i = 1; i <= NumCommBars; i++)
{
COleVariant CommandBarIndex((BYTE)i);
VariantInit(&v);
hr = OLEMethod(DISPATCH_PROPERTYGET, &v, pCommandBars, L"Item", 1, CommandBarIndex);
if (FAILED(hr)) continue;
pCommandBar = v.pdispVal;
VariantInit(&v);
hr = OLEMethod(DISPATCH_PROPERTYGET, &v, pCommandBar, L"Controls", 0);
if (FAILED(hr)) continue;
pCommandBarControls = v.pdispVal;
VariantInit(&v);
hr = OLEMethod(DISPATCH_PROPERTYGET, &v, pCommandBarControls, L"Count", 0);
if (FAILED(hr)) continue;
INT NumControls = v.intVal;
for (INT j = 1; j <= NumControls; j++)
{
COleVariant CommandBarControlIndex((BYTE)j);
VariantInit(&v);
hr = OLEMethod(DISPATCH_PROPERTYGET, &v, pCommandBarControls, L"Item", 1, CommandBarControlIndex);
if (FAILED(hr)) continue;
pCommandBarControl = v.pdispVal;
VariantInit(&v);
hr = OLEMethod(DISPATCH_PROPERTYGET, &v, pCommandBarControl, L"Caption", 0);
if (FAILED(hr)) continue;
CString ControlCaption(v.bstrVal);
if (ControlCaption.Find("MyCaption") != -1)
{
OLEMethod(DISPATCH_METHOD, NULL, pCommandBarControl, L"Delete", 0);
}
pCommandBarControl->Release();
}
pCommandBar->Release();
pCommandBarControls->Release();
}
OLEMethod(DISPATCH_METHOD, NULL, pWApp, L"Quit", 0);
pCommandBars->Release();
pWApp->Release();
}
}
CoUninitialize();
http://stackoverflow.com/questions/909314/how-can-i-remove-a-ms-word-add-in-button
- remove an add-in from MS Word
- Question- Remove empty elements from an array in Javascript
- HOWTO: Get the project flavor (subtype) of a Visual Studio project from an add-in
- Programming Word Add-In Component
- How to remove native support from an Android Project in eclipse because eclipse is showing errors in
- How to remove Duplicates from an Array
- Remove an element from Javascript Array
- remove duplicated value in an array
- Remove duplicate elements in an array
- add an vsftp user in linux
- Add text to an image in Java
- Hello Word Outlook Add-In using C#
- Add/Remove ISAPI Filter to/from IIS Automatically Using Delphi
- Add/Remove ISAPI Filter to/from IIS Automatically Using Delphi
- Add or remove buttons from message dialog boxes
- How to add/remove applications from ‘Open With’ window
- [LeetCode]Add Binary&Climbing Stairs&Remove Duplicates from Sorted List
- LeetCode 83. Remove Duplicates from Sorted List Add to List
- 法线向量
- Android平板电脑不能全屏显示的问题
- 后台线程与UI线程问题:解决“线程间操作无效: 从不是创建控件xxx的线程访问它”
- PHP面向对象的基础
- 基本类型与包装类
- remove an add-in from MS Word
- 汇编语言1—6章笔记
- Java高级编程——泛型类型
- 五个常用MySQL图形化管理工具
- qt4 控件
- 同一个表统一界面修改不同字段的值 关闭 开启
- 蒙特卡洛法求圆周率
- 对于mysql连接池8小时后自动待机问题
- source insight如何删除已加载的project, remove project,移除project,移除工程 出错,删除工程列表 .