使用Excel VBA计算跟进电子邮件 [英] Count Followup Emails using Excel VBA
问题描述
我正在使用Office 2013,并且试图在我的一个电子邮件文件夹中获取后续项目的计数,并且此值将被写入单元格中.
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.
因此,在添加Outlook对象库参考之后,我将使用以下代码:
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
由于某种原因,即使至少有一封电子邮件被标记为跟进",我仍将跟进"计数保持为" 0 ".
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
其中一封电子邮件的Flagstatus为 2 ,并且在测试过程中在Msgbox中也显示相同的内容.
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?
推荐答案
MSDN表示OlFlagStatus枚举:
MSDN says the OlFlagStatus enumeration:
...已过时,不打算在您的代码中使用.
... is deprecated and is not intended to be used in your code.
相反,请尝试使用MailItem.FlagRequest
属性.例如
Instead, try the MailItem.FlagRequest
property. E.g.
Set FollowupItms = itms.Restrict("[FlagRequest] = 'Follow up'")
您可以在以下位置找到有关MSDN上MailItem.FlagRequest
属性的信息:
http://msdn.microsoft.com/zh-cn/library/office/ff861323(v = office.14).aspx .
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 .
这篇关于使用Excel VBA计算跟进电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!