How many messages?

  • Thread starter Thread starter Grod
  • Start date Start date
G

Grod

How can one determine how many messages are in a folder?

I saw a reference to a Count property but I think that refers to CDO
and I don't think I am using CDO.

Thanks.
 
Each Outlook folder (MAPIFolder) has an Items collection. Items.Count will
tell you how many items are in the folder. If the folder is a calendar
folder then recurring items only count once for each set of recurrences
unless you set the IncludeRecurrences flag of the Items collection. However,
open ended recurring items would then return an impossibly large number
since they never end.
 
By default your are probably using Outlook VBA. If you check the References dialog, you will see that the 'Microsoft Outlook 11.0 Object Library' (or whatever version you are using) is selected - that's VBA. To use CDO, you need to set a reference to the 'Microsoft CDO 1.21 Library'.

This code will give you a message count for the active folder:

Sub Test()
Dim objFolder As Outlook.MAPIFolder, objItems As Outlook.Items

Set objFolder = Application.ActiveExplorer.CurrentFolder
Set objItems = objFolder.Items
Debug.Print "Message count: " & objItems.Count
End Sub
 
Back
Top