Count Followup Emails using Excel VBA

我怕爱的太早我们不能终老 提交于 2019-12-11 02:44:18

问题


I am using Office 2013 and I am trying to get a count of the followup items in one of my email folders and this value will be written into a cell.

So I am using the below code after adding the Outlook Object Library reference:

Dim Folder As Outlook.MAPIFolder

Dim objOL As Outlook.Application
Set objOL = New Outlook.Application

MailboxName = "mymailboxhere"
Main_Folder_Name = "Inbox"
Sub_Folder_Name = "Test"

Set Folder = Outlook.Session.Folders(MailBoxName).Folders(Main_Folder_Name).Folders(Sub_Folder_Name)

Dim itms As Outlook.Items
Set itms = Folder.Items

Dim FollowupItms As Outlook.Items
Set FollowupItms = itms.Restrict("[FlagStatus] = 2")

Followup = FollowupItms.Count
Worksheets("Sheet1").Range("A1").Value = Followup

For some reason I keep getting the Followup count as 0 even though there is at least an email flagged as followup.

To test I have tried the below:

For Each Msg In itms
MsgBox Msg.FlagStatus
Next

And the Flagstatus of one of the emails is 2 and the same shows in the Msgbox during the test.

The code works fine when counting emails that are UnFlagged or emails that are marked as Completed.

This makes absolutely no sense to me. Any thoughts?


回答1:


MSDN says the OlFlagStatus enumeration:

... is deprecated and is not intended to be used in your code.

(See http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.olflagstatus(v=office.14).aspx for details)

Instead, try the MailItem.FlagRequest property. E.g.

Set FollowupItms = itms.Restrict("[FlagRequest] = 'Follow up'")

You can find info on the MailItem.FlagRequest property on MSDN at http://msdn.microsoft.com/en-us/library/office/ff861323(v=office.14).aspx .



来源:https://stackoverflow.com/questions/25922611/count-followup-emails-using-excel-vba

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