【发布时间】: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
我们怎样才能做类似的事情,也可以在内联编辑器中工作,最好使用透明的单一功能。
【问题讨论】: