我需要对我在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的某些默认行为会被破坏。例子:
现在可能还有更多功能被打破。我不知道为什么会这样。造成这种情况的原因是什么,我们可以采取哪些措施来防止这种情况发生?
答案 0 :(得分:1)
您必须使用特定属性从内联响应中获取Word文档:Explorer.ActiveInlineResponseWordEditor。