• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Excel VBA to find a Specific mail in Outlook, Open it and Reply to it.

Hi,


I am trying to find mails with the relevant Subject from the outlook and then "replytoall" with a given format in the Body.

I have used the following code for searching the mails.

Sub Test()

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(olFolderInbox)
i = 1

For Each olMail In Fldr.Items
If InStr(olMail.Subject, "Application for Privilege Leave - Leave ID - Dev-PL-45252-4") <> 0 Then
olMail.Display

i = i + 1
End If
Next olMail
End Sub

This is working. With this i am able to search and display the desired mail. Now what i need is to Replyall with the same subject and a prescribed body and signature.

It is similar to when we open up an mail in outlook and click on the Reply to All button.

I want it to get triggered from excel.

Could anyone help me with this please..
 
Add this to ^olMail.Display & check

Code:
olMail.Reply
Reply.Body = "test reply" & vbCrLf & BR
 
Back
Top