在Outlook 2013中调用功能区按钮 [英] Invoke Ribbon button in Outlook 2013

查看:131
本文介绍了在Outlook 2013中调用功能区按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个Outlook加载项.我们需要像取消分配"按钮一样,在TaskItem Inspector窗口中以编程方式取消任务分配.

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.

人们会认为调用TaskItem.CancelResponseState()可能有效.尽管它确实取消了分配,但也使任务处于不可分配状态.功能区上的分配任务"按钮被禁用.

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.

在Outlook 2007和2010中,我们可以为取消分配"按钮获取CommandBarButton对象,并调用其Execute()方法.这给了我们想要的行为.但是,在Outlook 2013中,此命令栏按钮不再存在.这并不奇怪,因为Inspector命令栏在2007年被Ribbon取代.但是CommandBarButton对象仍然以编程方式存在,以实现向后兼容.借助Outlook 2013,Microsoft终于删除了该对象.

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?

推荐答案

您可以尝试使用兑换及其 SafeRibbon 对象:

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

编辑.在C#中,它将类似于以下内容(假设您将Redemption添加到了项目引用中):

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

这篇关于在Outlook 2013中调用功能区按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆