Send mail if today is the Birthday. [Solved/Closed]

Posts
368
Registration date
Monday February 7, 2011
Status
Contributor
Last seen
September 30, 2013
- Apr 14, 2011 at 04:47 AM - Latest reply:  tinyronny
- Feb 5, 2018 at 01:13 PM
Hello,

I have a Excel sheet containg profile of some employee like this:

Name ID Date of Birth
Rahul 335221 15/01/1986
Rose 325645 13/03/1980

I would like that if today is the birthday of the any employee an Happy Birthday mail should be send to them by outlook.

Could you please help me out.


See more 

8 replies

Best answer
Posts
368
Registration date
Monday February 7, 2011
Status
Contributor
Last seen
September 30, 2013
- Apr 15, 2011 at 04:15 AM
1
Thank you
Eureka!

I Got the code for this problem

Suppose that person name in column C,
Date of Birth in column D,
and E-Mail id in Column E.

Sub bdMail()  
Dim OutApp As Object  
Dim OutMail As Object  
Dim cell As Range  
Dim lastRow As Long  
Dim dateCell As Date  

Application.ScreenUpdating = False  
Set OutApp = CreateObject("Outlook.Application")  
OutApp.Session.Logon  
lastRow = Range("A" & Rows.Count).End(xlUp).Row  
On Error GoTo cleanup  
    For Each cell In Range("D2:D" & lastRow)  
    dateCell = cell.Value  
    If Day(dateCell) = Day(Date) And Month(dateCell) = Month(Date) Then  
            Set OutMail = OutApp.CreateItem(0)  
            On Error Resume Next  
            With OutMail  
                .To = cell.Offset(0, 1).Value  
                .Subject = "Happy Birthday"  
                .Body = "Dear " & Cells(cell.Row, "C").Value _  
                        & vbNewLine & vbNewLine & _  
                        "Many Happy Returns of the Day " _  
                        & vbNewLine & vbNewLine _  
                        & vbNewLine & vbNewLine & _  
                        "Cheers," & vbNewLine & _  
                        "Rahul"  
                .send  
            End With  
            On Error GoTo 0  
            Set OutMail = Nothing  
        End If  
    Next cell  
cleanup:  
    Set OutApp = Nothing  
    Application.ScreenUpdating = True  
End Sub  



Cheers, :)
Rahul

Thank you, RWomanizer 1

Something to say? Add comment

CCM has helped 1684 users this month

Posts
1
Registration date
Thursday June 18, 2015
Last seen
June 18, 2015
- Jun 18, 2015 at 03:07 AM
Dear Rahul,

It was very very helpful. Many Thanks!

Could you please e-mail me this code by taking into consideration changing body text color, font and style.

Looking forward to getting your sooner reply!

BR,
Gunay
I was requested to come up with a system for sending birthday messages in outlook and my search is over thanks to you.
Posts
55835
Registration date
Monday February 1, 2010
Status
Moderator
Last seen
November 18, 2018
- Apr 15, 2011 at 04:37 AM
0
Thank you
Rahul,

You are a little genius!

Where on earth did you get this code?

Just curious, where in the code is the link to Outlook?

Best regards
Posts
368
Registration date
Monday February 7, 2011
Status
Contributor
Last seen
September 30, 2013
- Apr 15, 2011 at 04:49 AM
0
Thank you
In the following lines:

to create outlook object :
Set OutApp = CreateObject("Outlook.Application")  
OutApp.Session.Logon  


and work with outlook in the following codes:

Set OutMail = OutApp.CreateItem(0)  
            On Error Resume Next  
            With OutMail  
            .................... 
so on.
Posts
55835
Registration date
Monday February 1, 2010
Status
Moderator
Last seen
November 18, 2018
- Apr 15, 2011 at 05:00 AM
0
Thank you
Thank you very much.

This thread is precious and should live on for posterity. I suggest you publish it in the faq even if it's not a frequently asked question.

I never thought that it was possible! Just fantastic Rahul and congratulations!

Very best regards
Posts
368
Registration date
Monday February 7, 2011
Status
Contributor
Last seen
September 30, 2013
- Apr 15, 2011 at 05:03 AM
0
Thank you
Thanks Ambucias,

I will post the same in FAQ.
Hi Boss,

Thanks for this code. Which is sending mail in plain sheet. is it possible to select background from outlook or insert a picture in mail, will be more colorful.