【问题标题】:Change an Outlook reply/forward message when composing using vba使用 vba 撰写时更改 Outlook 回复/转发消息
【发布时间】:2020-06-25 07:43:46
【问题描述】:

在回复、转发(或基本上对电子邮件项目进行任何形式的回复)时,我想更改电子邮件的正文。我知道如何在“发送”事件中执行此操作,但我宁愿在撰写之前执行此操作,以便我可以看到更改。 使用发送:

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

我们怎样才能做类似的事情,也可以在内联编辑器中工作,最好使用透明的单一功能。

【问题讨论】:

    标签: vba outlook


    【解决方案1】:

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

    实际操作示例:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-23
      • 1970-01-01
      • 2018-08-23
      • 1970-01-01
      相关资源
      最近更新 更多