使用vba进行编写时更改Outlook回复/转发消息

时间:2017-06-28 07:27:14

标签: vba outlook outlook-vba

在回复,转发(或基本上对电子邮件项目做出任何响应)时,我想更改电子邮件的正文。我知道如何在"发送"事件,但我宁愿在作曲前这样做,所以我可以看到变化。 使用发送:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    On Error Resume Next
    Set RegX = CreateObject("VBScript.RegExp")
    With RegX
        .pattern = "[a regular expression that I want to fix in the email body]"
        .Global = True
        .MultiLine = True
        .IgnoreCase = False
    End With
    Select Case Item.BodyFormat
        Case olFormatHTML
            Item.HTMLBody = RegX.Replace(Item.HTMLBody, "")
        Case Else
            'olFormatPlain, olFormatRichText, lFormatUnspecified?
            Item.Body = RegX.Replace(Item.Body, "")
    End Select
End Sub

我找到了一种在外部窗口(Inspectors.NewInspector)中触发撰写事件的方法,但很难找到包含在Outlook 2016中的内联编辑器中组成的回复的透明方式(Explorer.InlineResponse);

这是什么适用于"弹出"模态窗口响应:

Dim myOlApp As New Outlook.Application
Public WithEvents myOlInspectors As Outlook.Inspectors

Public Sub Initialize_handler()
    Set myOlInspectors = myOlApp.Inspectors
End Sub

Private Sub myOlInspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
    Set Item = Inspector.CurrentItem
    Set RegX = CreateObject("VBScript.RegExp")
    With RegX
        .pattern = "[a regular expression that I want to fix in the email body]"
        .Global = True
        .MultiLine = True
        .IgnoreCase = False
    End With
    Select Case Item.BodyFormat
        Case olFormatHTML
            Item.HTMLBody = RegX.Replace(Item.HTMLBody, "")
        Case Else
            'olFormatPlain, olFormatRichText, lFormatUnspecified?
            Item.Body = RegX.Replace(Item.Body, "")
    End Select
End Sub

我们如何能够在内联编辑器中执行类似的操作,最好使用透明的单个函数。

1 个答案:

答案 0 :(得分:1)

对于内联回复,您可以尝试使用Explorer.InlineReponse事件 - 该项将作为参数传递。

此实例示例:

Dim myOlApp As New Outlook.Application
Public WithEvents myOlExplorer As Outlook.Explorer

Public Sub Initialize_handler()
    Set myOlExplorer = myOlApp.ActiveExplorer
End Sub

Private Sub myOlExplorer_InlineResponse(ByVal Item As Object)
    ' do things to the Item here in the inline response
End Sub
相关问题