Invoke Ribbon button in Outlook 2013

大憨熊 提交于 2019-12-11 03:46:29

问题


We have an Outlook add-in. We need to programmatically cancel a task assignment in the TaskItem Inspector window, just the way the Cancel Assignment button does.

One would think that calling TaskItem.CancelResponseState() might work. Although it does cancel the assignment, it also leaves the task in an unassignable state. The Assign Task button on the ribbon is disabled.

In Outlook 2007 and 2010, we can get the CommandBarButton object for the Cancel Assignment button and call its Execute() method. This gives us the desired behavior. However, in Outlook 2013, this command bar button no longer exists. That's not surprising since Inspector command bars were replaced by the Ribbon in 2007. The CommandBarButton object still existed programmatically, though, for backward compatibility. With Outlook 2013, Microsoft has finally removed this object.

So the question is: Is there a way to programmatically "click" on a ribbon button? If not, is there another way to cancel the task assignment the way the ribbon button does it?


回答1:


You can try to use Redemption and its SafeRibbon object:

'simulate a click on the "Assign Task" button of an active Inspector
set sInspector = CreateObject("Redemption.SafeInspector")
sInspector.Item = Application.ActiveInspector
set Ribbon = sInspector.Ribbon
oldActiveTab = Ribbon.ActiveTab
Ribbon.ActiveTab = "Task"
set Control = Ribbon.Controls("Assign Task")
Control.Execute
Ribbon.ActiveTab = oldActiveTab 'restore the active tab

EDIT. In C#, it would be something like the following (assuming you added Redemption to your project references):

//simulate a click on the "Assign Task" button of an active Inspector
Redemption.SafeInspector sInspector = new Redemption.SafeInspector();
sInspector.Item = Application.ActiveInspector;
Redemption.SafeRibbon Ribbon = sInspector.Ribbon;
string oldActiveTab = Ribbon.ActiveTab;
Ribbon.ActiveTab = "Task";
Redemption.SafeRibbonControl Control = Ribbon.Controls.Item("Assign Task");
Control.Execute();
Ribbon.ActiveTab = oldActiveTab; //restore the active tab


来源:https://stackoverflow.com/questions/22546860/invoke-ribbon-button-in-outlook-2013

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!