Macro Count emails in your inbox?

zabiullakhan

Active Member
Joined
Aug 30, 2010
Messages
310
Macro Count emails in your outlook inbox
Please help me step by step as am not able to get the count with the code below. i guess am missing some config on objOutlook.GetNamespace("MAPI") and from which folder do i get the count
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("MIS")
   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, , "MIS email count"
End Sub

Please help
 

Some videos you may like

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Ruddles

Well-known Member
Joined
Aug 24, 2010
Messages
5,785
I posted some code a month or so back which does exactly this. Do a search for ruddles and getnamespace.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,000
Messages
5,526,172
Members
409,685
Latest member
Bellybb

This Week's Hot Topics

Top