Consulting

Results 1 to 2 of 2

Thread: E-mail Catagories Count

  1. #1
    VBAX Newbie
    Joined
    Apr 2017
    Posts
    1
    Location

    E-mail Catagories Count

    Hello,

    Here is an operation that I've been provided. This function will ask for a start date and end date, then searches for the currently selected folder and displays a count of each category in that selected folder.

    ----------------------------------------------------------

    Sub CategoriesEmails()

    Dim oFolder As MAPIFolder
    Dim oDict As Object
    Dim sStartDate As String
    Dim sEndDate As String
    Dim oItems As Outlook.Items
    Dim sStr As String
    Dim sMsg As String


    On Error Resume Next
    Set oFolder = Application.ActiveExplorer.CurrentFolder

    Set oDict = CreateObject("Scripting.Dictionary")

    sStartDate = InputBox("Type the start date (format MM/DD/YYYY)")
    sEndDate = InputBox("Type the end date (format MM/DD/YYYY)")

    Set oItems = oFolder.Items.Restrict("[Received] >= '" & sStartDate & "' And [Received] <= '" & sEndDate & "'")
    oItems.SetColumns ("Categories")

    For Each aitem In oItems
    sStr = aitem.Categories
    If Not oDict.Exists(sStr) Then
    oDict(sStr) = 0
    End If
    oDict(sStr) = CLng(oDict(sStr)) + 1
    Next aitem

    sMsg = ""
    For Each aKey In oDict.Keys
    sMsg = sMsg & aKey & ": " & oDict(aKey) & vbCrLf
    Next
    MsgBox sMsg

    Set oFolder = Nothing

    End Sub

    -------------------------------------------

    What I need help with is how to I modify this operation to search through all subfolders. Can someone take a look at what I've posted and advise how to do that? Please let me know if there's anything else you need. This is for Outlook 2016 if that's info required.

    Thank you in advance

  2. #2
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location

    Recursively process folders and their subfolders

    Recursively processing folders and any number of subfolder levels is shown here.

    http://www.outlookcode.com/codedetail.aspx?id=628

    A practical example.

    http://vboffice.net/en/developers/ex...2&cmd=showitem
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

Tags for this Thread

Posting Permissions

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