Consulting

Results 1 to 2 of 2

Thread: VBA for count of emails in a folder and subfolder

  1. #1
    VBAX Newbie
    Joined
    Jan 2020
    Posts
    2
    Location

    VBA for count of emails in a folder and subfolder

    I want to count how many emails are in a folder (including sub folders) and outlook is not providing it. If I have a folder called '2020' whats some good code to tell me how many emails total are in that folder and subfolders?
    Thanks

  2. #2
    You will need a macro

    Sub CountContents()
    Dim cFolders As Collection
    Dim olFolder As Outlook.Folder
    Dim SubFolder As Folder
    Dim olNS As Outlook.NameSpace
    Dim lngCount As Long: lngCount = 0
        Set cFolders = New Collection
        Set olNS = GetNamespace("MAPI")
        cFolders.Add olNS.PickFolder
        Do While cFolders.Count > 0
            Set olFolder = cFolders(1)
            cFolders.Remove 1
            lngCount = lngCount + olFolder.items.Count
            For Each SubFolder In olFolder.folders
                cFolders.Add SubFolder
            Next SubFolder
        Loop
        MsgBox lngCount & " items"
    lbl_Exit:
        Set olFolder = Nothing
        Set SubFolder = Nothing
        Exit Sub
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •