问题
When replying, forwarding (or basically doing any sort of response to an email item), I would like to change the body of the email. I know how to do this on the "send" event, but I would rather do this before composing so I can see change. Using send:
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
I found a way to trigger the compose event in the external windows (Inspectors.NewInspector) but have difficulty finding a transparent way that includes a reply composed in the inline editor in Outlook 2016 (Explorer.InlineResponse);
Here's what works for the "popped out" modal windows response:
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
How can we do something similar that also works in the inline editor, preferably using a transparent single function.
回答1:
For the inline replies, you can try to use Explorer.InlineReponse event - the Item will be passed as a parameter.
Example of this in action:
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
来源:https://stackoverflow.com/questions/44796134/change-an-outlook-reply-forward-message-when-composing-using-vba