Consulting

Results 1 to 2 of 2

Thread: Count emails within subfolders and possibly store it in a variable.

  1. #1

    Count emails within subfolders and possibly store it in a variable.

    Just need help The code below currently counts the total # of emails. I want to edit the code to count the amount mail within subfolders which are under the inbox and possibly store it in a variable. E.g some sub folders within the inbox are Folder1, Folder2, Folder3.




    Dim olApp As Outlook.Application
    Dim olNs As NameSpace
    Dim Fldr As MAPIFolder
    Set olApp = New Outlook.Application
    Set olNs = olApp.GetNamespace("MAPI")
    Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
    MsgBox Fldr.Items.Count
    Set Fldr = Nothing
    Set olNs = Nothing
    Set olApp = Nothing

  2. #2
    if there are subfoders within subfolders, do you want to count all?
    if so you would need some recursive routine

    you could try like
    Dim cnt As Collection
    Sub allfolders(f As MAPIFolder)
    Dim subf As MAPIFolder
    cnt.Add f.Items.Count, f.Name
    For Each subf In f.Folders
        allfolders subf
    Next
    
    End Sub
    Sub getall()
    Dim ibox As MAPIFolder
    Set cnt = New Collection
    Set ibox = Session.GetDefaultFolder(olFolderInbox)
    allfolders ibox
    End Sub
    each folder will be added to the collection, indexed by name, note this particular code will error if folder structure can have multiple subfolder with same name

    return results like msgbox cnt("inbox") or any other folder name

Posting Permissions

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