2017-06-28 128 views
0

當回覆,轉發(或基本上對電子郵件進行任何形式的回覆)時,我想更改電子郵件的正文。我知道如何在「發送」事件上做到這一點,但我寧願在撰寫之前這樣做,以便我可以看到變化。 使用Send:使用vba撰寫時更改Outlook回覆/轉發郵件

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內嵌編輯組成的答覆透明的方式(資源管理器.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

對於內嵌回覆,您可以嘗試使用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 
相關問題