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. #7
    Junior Member
    Join Date
    Aug 2018
    Posts
    12
    Rep Power
    0
    I got it! Had to Frankenstein some different codes together, but I got it to work. Check it out below (I used the full code which also pulls from a master file in excel to populate the data).

    Thanks for the help!


    Code:
    Sub Follow_Up()
    
    Dim c As Range, f As Range, source As Worksheet, master As Worksheet, s As String, StrBody As String
    
    Dim Fldr As Outlook.Folder
    Dim olMail As Variant
    Dim olReply As Outlook.MailItem
    Dim olItems As Outlook.Items
    Dim i As Integer
    Dim IsExecuted As Boolean
    
    Set source = Worksheets("Request List")
      Set master = Worksheets("Master List")
      Set olApp = New Outlook.Application
      
      For Each c In source.Range("A2", source.Cells(source.Rows.Count, "A").End(xlUp))
        With c
          If IsEmpty(.Offset(, 3).Value) = True Then GoTo NextC
          If .Offset(, 4).Value <> True Then GoTo NextC
          If .Offset(, 6).Value <> "NO" Then GoTo NextC
          
                Set olApp = New Outlook.Application
          Set olNs = olApp.GetNamespace("MAPI")
          
        Set Fldr = Session.GetDefaultFolder(olFolderInbox)
        IsExecuted = False
        Set olItems = Fldr.Items
        olItems.Sort "[Received]", True
        
        For i = 1 To olItems.Count
            Set olMail = olItems(i)
            If InStr(olMail.Subject, "Document Request: " & c.Offset(, 1).Value) > 0 Then
                If Not olMail.Categories = "Executed" Then
                    Set olReply = olMail.replyall
                    With olReply
            StrBody = "<BODY style=font-size:11pt;font-family:Calibri>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
                c.Offset(, 6).Value = "YES"  'Source sheet sent, YES.
                c.Offset(, 7).Value = Date   'Source sheet, Date sent.
                c.Offset(, 8).Value = Session.CurrentUser.Name
                    End With
                    Exit For
                    olMail.Categories = "Executed"
                   IsExecuted = True
                End If
            End If
        Next i
        End With
        
    NextC:
      Next c
      
      On Error Resume Next
      Set olMail = Nothing
      Set olApp = Nothing
    End Sub
    Last edited by pkearney10; 12-19-2018 at 11:26 PM.

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
  •