Forwarding Outlook Item as attachment and adding it to a category in the same VBA macro

ⅰ亾dé卋堺 提交于 2019-12-12 05:12:42

问题


I have a macro that works for forwarding multiple Outlook items as attachments. I've pasted that below, but I want it to also add the forwarded message(s) to a category in outlook. So, not only would it forward the items that are in my inbox to the recipient, but it would also mark those items in a certain category. This way I could track which items I have forwarded using the macro. As it is now, it will show me the item has been forwarded on such and such date, but that may have been just a regular forwarding action. Hence the need for the macro to add the item to a specialized category.

Sub ForwardSelectedItems()

On Error Resume Next

Dim objItem As Outlook.MailItem

If Application.ActiveExplorer.Selection.Count = 0 Then
   MsgBox ("No item selected")
   Exit Sub
End If

For Each objItem In Application.ActiveExplorer.Selection
    Set objMsg = objItem.Forward()
    With objMsg
        .Attachments.Add objItem, olEmbeddeditem
        .Subject = "example"
        .To = "example@example.com"
        .Body = “”
        .Send
    End With

Next

Set objItem = Nothing
Set objMsg = Nothing

End Sub

回答1:


The Categories property of the MailItem class allows to set a string representing the categories assigned to the Outlook item. Here is what MSDN states:

Categories is a delimited string of category names that have been assigned to an Outlook item. This property uses the character specified in the value name, sList, under HKEY_CURRENT_USER\Control Panel\International in the Windows registry, as the delimiter for multiple categories. To convert the string of category names to an array of category names, use the Microsoft Visual Basic function Split.

Note, you can use the Categories property of the Namespace class to get a Categories object that represents the set of Category objects available. This property represents the Master Category List, which is the set of Category objects that can be applied to Outlook items contained by the NameSpace object, and applies to all users of that namespace.

Also you may consider specifying the SaveSentMessageFolder for the mail item. The property allows to set a Folder object that represents the folder in which a copy of the e-mail message will be saved after being sent. So, you can easily recognize the auto-forwarded messages.



来源:https://stackoverflow.com/questions/30606625/forwarding-outlook-item-as-attachment-and-adding-it-to-a-category-in-the-same-vb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!