在 Outlook VBA 中更新电子邮件主题

Yas*_*ier 5 outlook vba

我正在尝试创建一个按钮控制的宏来更改电子邮件的主题。遵循这个线程我设法想出了这个:

Public Sub Confidential()

Dim Item As Outlook.MailItem
Dim oInspector As Inspector
Dim strSubject As String

Set oInspector = Application.ActiveInspector
If oInspector Is Nothing Then
    Set Item = Application.ActiveExplorer.Selection.Item(1)
Else
   Set Item = oInspector.CurrentItem
End If

strSubject = Item.Subject

' Remove previous Confidential and Legally Privileged
strSubject = Replace(strSubject, "Confidential and Legally Privileged ", "")

' Prefix subject with Confidential and Legally Privileged
strSubject = "Confidential and Legally Privileged " & strSubject

' Set the message subject
Item.Subject = strSubject


Set Item = Nothing
Set oInspector = Nothing


End Sub
Run Code Online (Sandbox Code Playgroud)

IF 语句是我尝试覆盖基础的尝试:当设置 ActiveInpector 时,用户可以在弹出窗口中编辑电子邮件,或者当设置ActiveExplorer.Selection 时,用户可以在阅读窗格中编辑电子邮件。

问题在于,虽然在第一种情况下宏按预期工作,但在第二种情况下主题没有改变(即使我在调试代码时可以看到它发生变化)。更有趣的是,如果消息被选择但未编辑(即用户没有单击“回复”按钮),则宏可以很好地更改消息列表中的主题。

现在,我找到了这个帖子,但是 a) 它已经有 6 年多了,b) 指向的论坛已经不存在了。正如其中所建议的,我尝试过Item.Save方法,但除了用原始主题关闭编辑后的消息之外,它似乎没有做任何事情。

Yas*_*ier 3

感谢 @Ryan Wildry 的回答:如果在资源管理器窗格中编辑电子邮件,请使用该.Display方法强制弹出窗口,然后使用它:

Dim Item As Outlook.MailItem
Dim oInspector As Inspector
Set oInspector = Application.ActiveInspector

If oInspector Is Nothing Then
    Set Item = Application.ActiveExplorer.Selection.Item(1)
    Item.Display   'Force the po-up
    Set oInspector = Application.ActiveInspector  'Reassign oInpsector and Item again
    Set Item = oInspector.CurrentItem
Else
   Set Item = oInspector.CurrentItem
End If
Run Code Online (Sandbox Code Playgroud)