【发布时间】:2021-06-30 02:43:52
【问题描述】:
我需要对我在 Outlook 2016 中转发或回复的电子邮件执行修改。
以下代码在 InlineResponse 窗口中执行修改(将正则表达式值替换为空):
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)
' first replace using the word editor
Dim oDoc As Word.Document
Dim wdSelection As Word.Selection
Set oDoc = Item.GetInspector.WordEditor
Set wdSelection = oDoc.Application.Selection
wdSelection.Find.ClearFormatting
wdSelection.Find.replacement.ClearFormatting
With wdSelection.Find
.Text = "SPECIFIC TEXT WITH A VARIABLE LENGTH OF SPACES OF DIFFERENT KINDS AFTER THAT I NEED TO INCLUDE [!a-zA-Z0-9]*([a-zA-Z0-9])" ' my regex goes in here the a-zA-Z0-9 part is to work around the non-greedy regex.
.replacement.Text = "\1"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
wdSelection.Find.Execute Replace:=wdReplaceAll
End Sub
当我运行这段代码(总体上运行良好)时,Outlook 的一些默认行为被破坏了。
例子:
- 草稿消息未保存。如果我点击回复,请在内联响应窗口中输入一些内容并留下该消息,当返回时,工作就消失了
- 无法从剪贴板粘贴
也许更多的功能被破坏了。
是什么原因造成的,我们可以做些什么来防止这种情况发生?
【问题讨论】: