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. #1
    Junior Member
    Join Date
    Aug 2018
    Posts
    12
    Rep Power
    0

    VBA to Reply All To Latest Email Thread

    Hello,

    I'm trying to build a macro that searches my inbox for a subject line (in this example "REQUEST FOR OVERTIME"), opens the most recent email, and reply all. My macro is a little more nuanced, but borrowed from the example I found online below.

    The issue is that it's opening ALL emails with the subject line "REQUEST FOR OVERTIME," not just the most recent. What should I add to this in order to just open the latest message?

    Thanks!


    Code:
    Sub ReplyMail_No_Movements()
    
    Dim olApp As Outlook.Application
    Dim olNs As Namespace
    Dim Fldr As MAPIFolder
    Dim olMail As Variant
    Dim i As Integer
    
    
    Set olApp = New Outlook.Application
    Set olNs = olApp.GetNamespace("MAPI")
    Set Fldr = olNs.GetDefaultFolder(olFolderSentMail)
    i = 1
    
    For Each olMail In Fldr.Items
    
    If InStr(olMail.Subject, "REQUEST FOR OVERTIME") <> 0 Then
            
                Set replyall = olMail.replyall
                With 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
    
    i = i + 1
    End If
    
    Next olMail
    
    Set olMail = Nothing
    Set olApp = Nothing
    
    End Sub


    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.eileenslounge.com/viewtopic.php?p=312533#p312533
    https://www.eileenslounge.com/viewtopic.php?f=44&t=40373&p=312499#p312499
    https://www.eileenslounge.com/viewtopic.php?p=311844#p311844
    https://archive.org/download/wlsetup-all_201802/wlsetup-all.exe
    https://www.eileenslounge.com/viewtopic.php?p=311826#p311826
    https://www.eileenslounge.com/viewtopic.php?f=37&t=40261&p=311783#p311783
    https://www.eileenslounge.com/viewtopic.php?p=310916#p310916
    https://www.eileenslounge.com/viewtopic.php?p=310720#p310720
    https://www.eileenslounge.com/viewtopic.php?f=56&t=40034&p=310171#p310171
    https://www.eileenslounge.com/viewtopic.php?p=310110#p310110
    https://www.eileenslounge.com/viewtopic.php?p=310024#p310024
    https://www.eileenslounge.com/viewtopic.php?p=309121#p309121
    https://www.eileenslounge.com/viewtopic.php?p=309101#p309101
    https://www.eileenslounge.com/viewtopic.php?p=308945#p308945
    https://www.eileenslounge.com/viewtopic.php?f=30&t=39858&p=308880#p308880
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 04-07-2024 at 12:53 PM. Reason: Added Code Tags

Similar Threads

  1. Replies: 185
    Last Post: 05-22-2024, 10:02 PM
  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
  •