I'm trying to use VBA to search a folder in my Outlook inbox and have it reply to the most recent email with the given subject. So far I've got the following code:
Dim Fldr As Outlook.Folder
Dim olMail As Outlook.MailItem
Dim olReply As Outlook.MailItem
Dim olItems As Outlook.Items
Dim i As Integer
'Dim IsExecuted As Boolean
Set Fldr = Session.GetDefaultFolder(olFolderInbox).folders("Refund Correspondence")
' IsExecuted = False
Set olItems = Fldr.Items
olItems.Sort "[Received]", True
For i = 1 To olItems.Count
Set olMail = olItems(i)
If InStr(olMail.subject, Me.Vendor_Client & " Tax Refund Request - " & Me.Vendor_Name) > 0 Then
' If Not IsExecuted Then
If Not olMail.categories = "Executed" Then
Set olReply = olMail.ReplyAll
With olReply
.BodyFormat = olFormatHTML '''This is where I'm running into trouble
.Display
.To = Me.Vendor_E_mail
.subject = Me.Vendor_Client & " Tax Refund Request - " & Me.Vendor_Name
End With
Exit For
olMail.categories = "Executed"
' IsExecuted = True
End If
End If
Next i
In other projects I've worked on I've only needed to create an email from scratch, and I've been able to use Ron DeBruin's RangeToHTML(selection) to paste a specified range into my email using an existing email template containing specific words and the replace function to replace the words with tables. For this project, however, I want to reply to an existing email chain. Since I can't refer to an email template and replace a word with the table I want to insert, I'm at a loss. The .bodyFormat = olFormatHTML does work to reply to the email I want it to with the rest of the chain below my response, but I don't know how to paste the table I want into the email after that. I tried using the .HTMLBody = rangetohtml(selection) function, but that only created a new email without the previous emails on the chain.