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

编程入门 行业动态 更新时间:2024-10-28 02:23:02
本文介绍了在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方法强制弹出窗口,然后使用它:

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中更新电子邮件主题

本文发布于:2023-06-08 23:37:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/591029.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:电子邮件   主题   Outlook   VBA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!