Multiple Email body to same recipient

brt21

New Member
Joined
Oct 1, 2015
Messages
25
Hi,

I wrote a VBA Code to send a mail to the recipient based on a criterion. My next step is a bit complex and I am not sure how to proceed.

Problem:

I have a criterion, passing which, a mail will be sent to a recipient. But there shall be several instances where the criterion is TRUE and more than one mail will be sent to the same person. In the actual application, a person could receive upto 10 mails with a slight modification in the email body. I would like to group the information to be written in the email body and send it to the recipient as one mail. Please have a look at the file here. Based on the code, the criterion is if the value in H:H is <= -2, the programmed Actions will be performed. Assuming that the criterion is TRUE and more than one set of detail have to be sent to the same Person (based on Email in E:E), I would like to send it as one mail.

Ideas:

inserting an additional criterion after the first set of FOR and IF Statement and the new criterion is to check if there are more than one instance of the email recipient. If the condition is TRUE, insert a FOR Statement to gather data from all the possible mails to be sent to each recipient.

I am still learning VBA and not sure how to proceed with this idea. Any suggestions or sample Code is highly appreciated. Meanwhile, I will try to solve the query myself.

Thank you!

Regards,
Bharath
Code:
Private Sub CommandButton1_Click()
    Dim OutApp As Object
    Dim OutMail As Object
    Dim date1 As Date
    Dim today As Date
    Dim x As Long
    lastrow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
    
    For x = 2 To lastrow
        date1 = Cells(x, 6).Value
        today = DateValue(Date)
        n = DateDiff("d", today, date1)
    
        If Cells(x, 8) <= -2 Then
            Set OutApp = CreateObject("Outlook.Application")
            Set OutMail = OutApp.CreateItem(0)
            
            With OutMail
                .To = Cells(x, 5).Value
                .CC = ""
                .BCC = ""
                .Subject = "Payment Reminder"
                .Body = "Hallo " & Cells(x, 2).Value & " " & Cells(x, 3).Value & vbNewLine & _
                        vbNewLine & _
                        "Please pay your bill." & vbNewLine & _
                        vbNewLine & _
                        "Regards," & vbNewLine & _
                        "Bharath"
                .Send
            End With
            
            Cells(x, 7) = "Yes"
            Cells(x, 7).Interior.Color = xlNone
            Cells(x, 7).Font.ColorIndex = 3
            Cells(x, 7).Font.Bold = True
        End If
    
    Next
    
    Set OutApp = Nothing
    Set OutMail = Nothing
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
The way I would do it would be to create a unique set of emails, and then filter by each email that has value <=-2. From there, if more than one, I don't know what you want in the body. Normally, one would have an invoice number or such and a date that it was due and maybe number of day past due.
 
Upvote 0
The way I would do it would be to create a unique set of emails, and then filter by each email that has value <=-2. From there, if more than one, I don't know what you want in the body. Normally, one would have an invoice number or such and a date that it was due and maybe number of day past due.

Hi Kenneth,

If you have tried the code with the excel file I attached, zou would have received a mail as follows:

"Hi Kobe Bryant,

Please pay your bill number 10001


Regards,
Bharath "

For example, if more than one instance pass my criterion, the person has to receive a mail like this:

"Hi Kobe Bryant,


Please pay your bill number 10001 and 10004


Regards,
Bharath "

<strike></strike>

And by filtering, do you mean through Excel or VBA?
I have not tried it through VBA.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top