在 Outlook VBA 中更新电子邮件主题 [英] Updating email subject in Outlook VBA

查看:30
本文介绍了在 Outlook VBA 中更新电子邮件主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个按钮控制的宏来更改电子邮件的主题.按照这个线程,我想出了这个:

I am trying to create a button-controlled macro that would change the topic of an email message. Following this thread I've managed to came up with this:

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 设置或用户可以在 阅读窗格 - 当ActiveExplorer.Selection 已设置.

The IF statement is my attempt to cover the bases: user can either edit the email in the pop-up window, when the ActiveInpector is set or user can edit it in the reading pane - when the ActiveExplorer.Selection is set.

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

Problem is in the fact that while in the first case the macro works as expected, in the second the subject is not changed (even while I can see it changing while debugging the code). What is even more interesting if the message is selected but not edited (i.e. user hasn't clicked "reply" button) the macro works fine changing the topic in the message list.

现在,我找到了 这个主题 但是 a) 它已经超过 6 年了并且 b) 指向不再存在的论坛.正如其中所建议的,我已经尝试了 Item.Save 方法,但除了关闭带有原始主题的已编辑消息之外,它似乎什么也没做.

Now, I've found this thread but a) it s over 6 years old and b) points to forum that doesn't exist anymore. As suggested in it, I've tried Item.Save method, but it doesn't seem to do anything except closing the edited message with original subject.

推荐答案

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

Answered thanks to @Ryan Wildry: if the email is edited in the explorer pane, use the .Display method to force a pop-up and then work with it:

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

这篇关于在 Outlook VBA 中更新电子邮件主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆