Count number of flagged Emails (1 Viewer)

Freshman

Registered User.
Local time
Today, 14:36
Joined
May 21, 2010
Messages
437
Hi all,

I'm using the code below to count the number of emails in an Inbox but I want to narrow it down to just the flagged emails.

Code:
Sub HowManyEmails()
Dim objOutlook As Object,
objnSpace As Object,
objFolder As Object
Dim EmailCount As Integer
Set objOutlook = CreateObject("Outlook.Application")
Set objnSpace = objOutlook.GetNamespace("MAPI")

    On Error Resume Next   
    Set objFolder = objnSpace.Folders("Personal Folders").Folders("Inbox").Folders("report's").Folders("Customer")   
    If Err.Number <> 0 Then   
    Err.Clear   
    MsgBox "No such folder."   
    Exit Sub   
    End If

EmailCount = objFolder.Items.Count   
Set objFolder = Nothing   
Set objnSpace = Nothing   
Set objOutlook = Nothing

MsgBox "Number of emails in the folder: " & EmailCount, , "email count"
End Sub
 

Freshman

Registered User.
Local time
Today, 14:36
Joined
May 21, 2010
Messages
437
Might very well be but I tried a few options but not sure how to use it (syntax) in the code I posted.
 

bastanu

AWF VIP
Local time
Today, 05:36
Joined
Apr 13, 2010
Messages
1,401
Maybe try something like this using Restrict to filter:
Code:
Sub HowManyFlaggedEmails()
Dim objOutlook As Object,
objnSpace As Object,
objFolder As Object
Dim EmailCount As Integer
Set objOutlook = CreateObject("Outlook.Application")
Set objnSpace = objOutlook.GetNamespace("MAPI")

    On Error Resume Next  
    Set objFolder = objnSpace.Folders("Personal Folders").Folders("Inbox").Folders("report's").Folders("Customer")  
    If Err.Number <> 0 Then  
    Err.Clear  
    MsgBox "No such folder."  
    Exit Sub  
    End If

EmailCount = objFolder.Items.Count

Dim FollowupCount as integer  
Dim itms As Object 'Outlook.Items
Set itms = objFolder.Items

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

FollowupCount = FollowupItms.Count




Set objFolder = Nothing  
Set objnSpace = Nothing  
Set objOutlook = Nothing

MsgBox "Number of emails in the folder: " & EmailCount & ", with " & FollowupCount & " flagged for Follow Up" , , "email count"
End Sub

Source: https://stackoverflow.com/questions/25922611/count-followup-emails-using-excel-vba
Cheers,
 

Freshman

Registered User.
Local time
Today, 14:36
Joined
May 21, 2010
Messages
437
Maybe try something like this using Restrict to filter:
Code:
Sub HowManyFlaggedEmails()
Dim objOutlook As Object,
objnSpace As Object,
objFolder As Object
Dim EmailCount As Integer
Set objOutlook = CreateObject("Outlook.Application")
Set objnSpace = objOutlook.GetNamespace("MAPI")

    On Error Resume Next 
    Set objFolder = objnSpace.Folders("Personal Folders").Folders("Inbox").Folders("report's").Folders("Customer") 
    If Err.Number <> 0 Then 
    Err.Clear 
    MsgBox "No such folder." 
    Exit Sub 
    End If

EmailCount = objFolder.Items.Count

Dim FollowupCount as integer 
Dim itms As Object 'Outlook.Items
Set itms = objFolder.Items

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

FollowupCount = FollowupItms.Count




Set objFolder = Nothing 
Set objnSpace = Nothing 
Set objOutlook = Nothing

MsgBox "Number of emails in the folder: " & EmailCount & ", with " & FollowupCount & " flagged for Follow Up" , , "email count"
End Sub

Source: https://stackoverflow.com/questions/25922611/count-followup-emails-using-excel-vba
Cheers,
Works like a charm!! Thanks a lot!
 

bastanu

AWF VIP
Local time
Today, 05:36
Joined
Apr 13, 2010
Messages
1,401
You're very welcome, good luck with your project!

Cheers,
 

Users who are viewing this thread

Top Bottom