Dear All,
I am using the coding below to count emails in each subfolder within the Inbox, but all it does is count 1 in each folder, does anyone know why it wont count all items in the folder. Here is the coding.
Sub Count_Items_In_Folders()
Dim objApp As Object
Dim namespace As namespace
Set objApp = CreateObject("Outlook.Application"
Set mynamespace = objApp.GetNamespace("MAPI"
Set myFolders = mynamespace.GetDefaultFolder(6)
Set mycollection = myFolders.Folders
For I = 1 To mycollection.Count
Set myfolder = mycollection.Item(I)
For Each myfolder In mycollection
If Err = 0 Then
Set objItem = myfolder.Items(I)
If objItem.UnRead Then
unreadm = unreadm + 1
Else
readm = readm + 1
End If
Err.Clear
End If
Next
MsgBox "Number of Unread Emails is :" & unreadm & ".", vbInformation
MsgBox "Number of Read Emails is :" & readm & ".", vbInformation
Next
End Sub
Thanks Rob.![[yoda] [yoda] [yoda]](/data/assets/smilies/yoda.gif)
I am using the coding below to count emails in each subfolder within the Inbox, but all it does is count 1 in each folder, does anyone know why it wont count all items in the folder. Here is the coding.
Sub Count_Items_In_Folders()
Dim objApp As Object
Dim namespace As namespace
Set objApp = CreateObject("Outlook.Application"
Set mynamespace = objApp.GetNamespace("MAPI"
Set myFolders = mynamespace.GetDefaultFolder(6)
Set mycollection = myFolders.Folders
For I = 1 To mycollection.Count
Set myfolder = mycollection.Item(I)
For Each myfolder In mycollection
If Err = 0 Then
Set objItem = myfolder.Items(I)
If objItem.UnRead Then
unreadm = unreadm + 1
Else
readm = readm + 1
End If
Err.Clear
End If
Next
MsgBox "Number of Unread Emails is :" & unreadm & ".", vbInformation
MsgBox "Number of Read Emails is :" & readm & ".", vbInformation
Next
End Sub
Thanks Rob.
![[yoda] [yoda] [yoda]](/data/assets/smilies/yoda.gif)