简体   繁体   English

使用 Excel VBA 计算后续电子邮件

[英]Count Followup Emails using Excel VBA

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.我正在使用 Office 2013 并且我正在尝试获取我的一个电子邮件文件夹中的后续项目的计数,并且该值将被写入一个单元格中。

So I am using the below code after adding the Outlook Object Library reference:所以我在添加 Outlook 对象库引用后使用以下代码:

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.出于某种原因,即使至少有一封电子邮件被标记为后续,我仍然将后续计数设为0

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.并且其中一封电子邮件的Flagstatus为2,并且在测试期间在Msgbox中显示相同。

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?有什么想法吗?

MSDN says the OlFlagStatus enumeration: MSDN 说 OlFlagStatus 枚举:

... 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) (有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.olflagstatus(v=office.14).aspx

Instead, try the MailItem.FlagRequest property.相反,请尝试使用MailItem.FlagRequest属性。 Eg例如

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 .您可以在 MSDN 上找到有关MailItem.FlagRequest属性的信息, 网址http://msdn.microsoft.com/en-us/library/office/ff861323(v=office.14).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM