Results 1 to 3 of 3

Thread: Macro to Search Specific Subject, find, & reply all - Outlook 2016

  1. #1
    VBAX Newbie
    Jun 2020

    Macro to Search Specific Subject, find, & reply all - Outlook 2016

    Title says it all.

    Needing to have a macro where it can search the inbox, sent, draft, & outbox, for the latest message containing a particular Subject line & reply all to (Trying to continue the threads of specific emails)

    How can I do this?
    Thank you in advance to all the resident Geniuses!

  2. #2
    Searching the inbox and its sub folders is not that difficult, but I fail to see the point of searching sent, draft, & outbox; and replies to sent or outbox messages would go to you.

    The following should get you started

    Option Explicit
    'Graham Mayor - - Last updated - 18 Jun 2020 
    Private Const sSubject As String = '"The text to find"
    Sub ProcessFolders()
    Dim cFolders As Collection
    Dim olFolder As Outlook.Folder
    Dim SubFolder As Folder
    Dim olNS As Outlook.NameSpace
        On Error Resume Next
        Set cFolders = New Collection
        Set olNS = GetNamespace("MAPI")
        cFolders.Add olNS.PickFolder
        Do While cFolders.Count > 0
            Set olFolder = cFolders(1)
            cFolders.Remove 1
            FindSubject olFolder
            For Each SubFolder In olFolder.folders
                cFolders.Add SubFolder
            Next SubFolder
        Set olFolder = Nothing
        Set SubFolder = Nothing
        Exit Sub
        GoTo lbl_Exit
    End Sub
    Private Sub FindSubject(iFolder As Folder)
    Dim olItem As Outlook.MailItem
    Dim olMsg As Outlook.MailItem
    Dim i As Long
        iFolder.items.Sort "[Received]", True
        For i = iFolder.items.Count To 1 Step -1
            Set olItem = iFolder.items(i)
            If TypeName(olItem) = "MailItem" Then
                If InStr(1, olItem.Subject, sSubject) > 0 Then
    Debug.Print olItem.Subject & vbTab & olItem.sender
                    Set olMsg = olItem.ReplyAll
                    'do stuff with olMsg
                    Exit For
                End If
            End If
        Next i
        Set olItem = Nothing
        Exit Sub
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes

  3. #3
    VBAX Newbie
    Jun 2020
    I'll give this a try, thank you!
    My reason behind needing this is because I generate allot of emails that require replying to the very latest reply within the thread.
    Sometimes, I have a draft already in progress, or an email is stuck in my outbox, or was already sent.
    Does this help?

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