【问题标题】:Add a subject to a new email with custom button使用自定义按钮向新电子邮件添加主题
【发布时间】:2015-12-21 02:38:19
【问题描述】:

我为 Outlook 2010 编写了一个插件,可将文本插入新的电子邮件主题和电子邮件正文。工作代码如下所示。

后来我向内置的新电子邮件选项卡功能区添加了一个自定义组,并使用默认名称 Button1 添加了一个按钮。当我运行加载项时,按钮显示正常。

我想单击此按钮并更改主题和正文内容。我尝试添加一个私有子 Button1_Click,其代码将主题更改为“主题示例”,将正文更改为“正文示例”,但无法使其工作。您可以将 Button1_Click 子添加到功能区代码中吗?请参见下面的 Addin 代码和ribbon1 代码。

Public Class ThisAddIn

Private WithEvents inspectors As Outlook.Inspectors

Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
    inspectors = Me.Application.Inspectors
End Sub

Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown

End Sub

Private Sub inspectors_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector) Handles inspectors.NewInspector
    Dim mailItem As Outlook.MailItem = TryCast(Inspector.CurrentItem, Outlook.MailItem)
    If Not (mailItem Is Nothing) Then
        If mailItem.EntryID Is Nothing Then
            mailItem.Subject = "This text was added by using code"
            mailItem.Body = "This text was added by using code"
        End If
    End If
End Sub

End Class

没有私有子按钮的 Ribbon1 代码1.单击。请告诉我如何编写此代码。

Public Class Ribbon1

Private Sub Ribbon1_Load(ByVal sender As System.Object, ByVal e As RibbonUIEventArgs) Handles MyBase.Load

End Sub

End Class

【问题讨论】:

    标签: outlook vsto outlook-addin outlook-2010


    【解决方案1】:

    VSTO 提供了两种自定义功能区 UI 的主要方法:

    本质上你需要为按钮添加onAction属性,然后在代码中添加相应的回调。

    在 MSDN 中的以下系列文章中阅读有关 Fluent UI(又名 Ribbon UI)的更多信息:

    要获取当前显示在检查器窗口中的 Outlook 项目,您可以使用 Application 类的 ActiveInspector 方法或使用您可以强制转换为 Inspector 类的 IRibbonControl.Context 属性。然后您可以使用CurrentItem 属性来获取 Outlook 项目。

    【讨论】:

    • 尤金,感谢您的快速回答。在发布问题之前,我成功创建了所有内容并且它有效。我只需要你向我展示我示例中例程的代码。
    • 要获取当前显示在检查器窗口中的 Outlook 项目,您可以使用 Application 类的 ActiveInspector 方法或使用您可以强制转换为 Inspector 类的 IRibbonControl.Context 属性。然后您可以使用CurrentItem 属性来获取 Outlook 项目。
    • 我解决了这个问题。此代码使其工作: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim application As Outlook.Application = Globals.ThisAddIn.Application Dim inspector As Outlook.Inspector = Application.ActiveInspector () Dim myMailItem As Outlook.MailItem = CType(inspector.CurrentItem, Outlook.MailItem) myMailItem.Subject = "此文本是使用代码添加的"
    猜你喜欢
    • 1970-01-01
    • 2011-11-08
    • 1970-01-01
    • 2014-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-13
    相关资源
    最近更新 更多