Quantcast
Channel: Excel IT Pro Discussions forum
Viewing all articles
Browse latest Browse all 11829

Count Followup Emails using Excel VBA

$
0
0

For full disclosure: I have also posted this question on SO and MrExcel, but I haven't got any responses yet, so I thought of seeking for help here :)

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?

Viewing all articles
Browse latest Browse all 11829

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>