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




Reply With Quote
Bookmarks