VBA for Outlook-使用权限更改主题行

时间:2018-12-19 21:19:47

标签: vba outlook outlook-vba

我正在尝试将传入电子邮件的主题行更改为仅主题行的最后11个字符。当我使用Item.Subject = Right(Item.Subject,11)时不起作用。

有人可以协助吗?

完整代码。

Sub ChangeSubjectForward(Item As Outlook.MailItem)
Item.Subject = Right(Item.Subject, 11) 
Item.Save
End Sub

2 个答案:

答案 0 :(得分:0)

我发现了另一个SO线程,该线程说您必须先打开一条消息才能修改该消息的主题。在显示项目后,我们可以使用ActiveInspector来获得该项目的句柄。然后,我们可以对其进行更改,保存并关闭。在尝试截断主题之前,我添加了一个检查以查看主题实际上是否超过11个字符。

尝试一下:

Public Sub ChangeSubjectForward(ByRef Item As Outlook.MailItem)
    Debug.Print Now                              '  This shows you when the code runs
    If Len(Item.Subject) > 11 Then
        Debug.Print "Subject is too long. Trimming..." '  This shows that we tried to truncate.

        Item.Display                             'Force the pop-up

        Dim thisInspector As Inspector
        Set thisInspector = Application.ActiveInspector

        Set Item = thisInspector.CurrentItem     ' Get the handle from the Inspector
        Item.Subject = Right$(Item.Subject, 11)
        Item.Save
        Item.Close
    End If
End Sub

答案 1 :(得分:0)

您可以创建一个macro rule,然后运行以下代码:

Sub save_to_dir_test1(mymail As MailItem)
Dim strID As String
Dim objMail As Outlook.MailItem

strID = mymail.EntryID
Set objMail = Application.Session.GetItemFromID(strID)
objMail.Subject = Right(m.Subject, 11)
objMail.Save
Set objMail = Nothing
End Sub

有关更多信息,请参考此链接:

Run a Script Rule: Change Subject then Forward Message

Getting the incoming email in outlook via VBA