Results 1 to 10 of 12

Thread: VBA to Reply All To Latest Email Thread

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    Patrick,

    Yes, this is one way to do it. I haven't tested it extensively, but seems to work

    Code:
    Sub ReplyMail_No_Movements()
    
        Dim olApp As Outlook.Application
        Dim olNs As NameSpace
        Dim Fldr As MAPIFolder
        Dim olMail As MailItem
        Dim objReplyToThisMail As MailItem
        Dim lngCount As Long
        Dim objConversation As Conversation
        Dim objTable As Table
        Dim objVar As Variant
        
        Set olApp = Session.Application
        Set olNs = olApp.GetNamespace("MAPI")
        Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
        
        
        lngCount = 1
        
        For Each olMail In Fldr.Items
            If InStr(olMail.Subject, "REQUEST FOR OVERTIME") <> 0 Then 'Text To Check
                Set objConversation = olMail.GetConversation
                Set objTable = objConversation.GetTable
                objVar = objTable.GetArray(objTable.GetRowCount)
                Set objReplyToThisMail = olApp.Session.GetItemFromID(objVar(UBound(objVar), 0))
                With objReplyToThisMail.ReplyAll
                    StrBody = "Hello " & "<br>" & _
                                "<p>Following up with the below. May you please advise?" & _
                                "<p>Thank you," & vbCrLf & vbCrLf & "<br>" & _
                                "<p>" & Session.CurrentUser.Name
                    .HTMLBody = StrBody & .HTMLBody
                    emailReady = True
                    .Display
                End With
            Exit For
            End If
        Next olMail
        
        Set olApp = Nothing
        Set olNs = Nothing
        Set Fldr = Nothing
        Set olMail = Nothing
        Set objReplyToThisMail = Nothing
        lngCount = Empty
        Set objConversation = Nothing
        Set objTable = Nothing
        If IsArray(objVar) Then Erase objVar
        
    End Sub
    Last edited by Excel Fox; 12-01-2018 at 09:43 AM. Reason: Appended The Missing .ReplyAll
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

Similar Threads

  1. Replies: 192
    Last Post: 08-30-2025, 01:34 AM
  2. Replies: 19
    Last Post: 04-20-2019, 02:38 PM
  3. Table Tests. And Thread Copy Tests No Reply needed
    By DocAElstein in forum Test Area
    Replies: 1
    Last Post: 11-20-2018, 01:11 PM
  4. Replies: 8
    Last Post: 04-13-2014, 02:38 PM
  5. Moving Current Latest Data To New Workbook
    By Terry in forum Excel Help
    Replies: 1
    Last Post: 01-19-2013, 12:37 AM

Posting Permissions

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