3

我已经进行了合理的“谷歌搜索”,但找不到我的问题的答案。

我有以下两个子程序。两者完全相同,除了第一个有“ForwardMailItem.Display”,第二个没有。结果是第一个生成的电子邮件草稿包含插入的文本“在此处测试”,而第二个生成的电子邮件不包含插入的文本。我有几个问题,希望有人可以帮助我。1)如何在不使用 .Display 方法的情况下成功地在我转发的电子邮件中插入新文本,因为 .InsertBefore 本身似乎并不能解决问题?2) .Display 在我的情况下除了直观地显示项目之外还有什么特别的作用?

Sub TestInsertBeforeWithDisplay()

    Dim NewMailItem As Outlook.MailItem
    Dim ForwardMailItem As Outlook.MailItem

    For Each NewMailItem In Application.Session.GetDefaultFolder(olFolderInbox).Items.Restrict("[Unread]=true")
        Set ForwardMailItem = NewMailItem.FORWARD
        ForwardMailItem.GetInspector.WordEditor.Characters(1).InsertBefore "testing here"
        ForwardMailItem.Display
        ForwardMailItem.Close olSave
    Next NewMailItem

End Sub

Sub TestInsertBeforeWithoutDisplay()

    Dim NewMailItem As Outlook.MailItem
    Dim ForwardMailItem As Outlook.MailItem

    For Each NewMailItem In Application.Session.GetDefaultFolder(olFolderInbox).Items.Restrict("[Unread]=true")
        Set ForwardMailItem = NewMailItem.FORWARD
        ForwardMailItem.GetInspector.WordEditor.Characters(1).InsertBefore "testing here"
        ForwardMailItem.Close olSave
    Next NewMailItem

End Sub
4

1 回答 1

1

有趣的问题。我不经常编写 Outlook 代码,但我认为答案是您必须关闭并保存 ActiveInspector:

Sub TestInsertBeforeWithDisplay()
Dim NewMailItem As Outlook.MailItem
Dim ForwardMailItem As Outlook.MailItem
Dim ActInsp As Outlook.Inspector

For Each NewMailItem In Application.Session.GetDefaultFolder(olFolderInbox).Items.Restrict("[Unread]=true")
    Set ForwardMailItem = NewMailItem.Forward
    Set ActInsp = ForwardMailItem.GetInspector
    With ActInsp
        .WordEditor.Characters(1).InsertBefore "testing here"
        .Close (olSave)
    End With
    ForwardMailItem.Close olSave
Next NewMailItem
End Sub

我能够复制您的问题,并且上面的代码修复了它。我不确定是否仍然需要保存ForwardMailItem.

于 2013-07-20T16:27:48.140 回答