Enright
07-28-2016, 08:59 AM
Hello!
So far, I have the code below that will look for a specific subject name in a specific folder "Refund Correspondence".
However, it seems that it opens any random e-mail with the designated subject name.
I can't figure out what to add so that it will only reply to the the most recent e-mail with the specified subject name.
Thanks!
Dim olApp As Outlook.Application
Dim olNs As NameSpace
Dim Fldr As MAPIFolder
Dim olMail As Variant
Dim I As Integer
Dim IsExecuted As Boolean
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox).Folders("Refund Correspondence")
IsExecuted = False
For Each olMail In Fldr.Items
If InStr(olMail.Subject, Me.Vendor_Client & " Tax Refund Request - " & Me.Vendor_Name) > 0 Then
If Not IsExecuted Then
With olMail.ReplyAll
.BodyFormat = olFormatHTML
.Display
.To = Me.Vendor_E_mail
.Subject = Me.Vendor_Client & " Tax Refund Request - " & Me.Vendor_Name
End With
IsExecuted = True
End If
End If
So far, I have the code below that will look for a specific subject name in a specific folder "Refund Correspondence".
However, it seems that it opens any random e-mail with the designated subject name.
I can't figure out what to add so that it will only reply to the the most recent e-mail with the specified subject name.
Thanks!
Dim olApp As Outlook.Application
Dim olNs As NameSpace
Dim Fldr As MAPIFolder
Dim olMail As Variant
Dim I As Integer
Dim IsExecuted As Boolean
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox).Folders("Refund Correspondence")
IsExecuted = False
For Each olMail In Fldr.Items
If InStr(olMail.Subject, Me.Vendor_Client & " Tax Refund Request - " & Me.Vendor_Name) > 0 Then
If Not IsExecuted Then
With olMail.ReplyAll
.BodyFormat = olFormatHTML
.Display
.To = Me.Vendor_E_mail
.Subject = Me.Vendor_Client & " Tax Refund Request - " & Me.Vendor_Name
End With
IsExecuted = True
End If
End If