【发布时间】:2016-08-24 23:07:39
【问题描述】:
我正在尝试创建一个按钮控制的宏来更改电子邮件的主题。在this thread 之后,我设法想出了这个:
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
IF 语句是我试图涵盖的基础:当 ActiveInpector 设置时,用户可以在弹出窗口中编辑电子邮件,或者用户可以在 reading pane 中编辑它 - 当 ActiveExplorer.Selection 设置时.
问题在于,在第一种情况下,宏按预期工作,而在第二种情况下,主题没有改变(即使在调试代码时我可以看到它在改变)。如果消息被选中但未编辑(即用户尚未单击“回复”按钮),则更有趣的是,宏可以很好地更改消息列表中的主题。
现在,我找到了this thread,但是 a) 它已经超过 6 年了,b) 指向的论坛已经不存在了。正如其中所建议的,我尝试了Item.Save 方法,但它似乎没有做任何事情,除了关闭带有原始主题的编辑消息。
【问题讨论】:
-
它会抛出任何错误吗?
-
不 - 执行没有问题,我可以看到
item.subject对象的变化,但它没有显示在屏幕上。 -
您在更改之前还是之后致电.Display?我在上面的代码中没有看到。
-
所以您尝试将主题从
Confidential and Legally Privileged更改为Confidential and Legally Privileged Confidential and Legally Privileged? -
@Om3r 不,有一个
replace方法可以删除已经存在的“机密....”文本:strSubject = Replace(strSubject, "Confidential and Legally Privileged ", "")