Send mail if today is the birthday.

Solved/Closed
RWomanizer Posts 365 Registration date Monday February 7, 2011 Status Contributor Last seen September 30, 2013 - Updated on Nov 28, 2018 at 02:01 PM
bkdroid13 Posts 11 Registration date Wednesday May 29, 2019 Status Member Last seen October 5, 2019 - Jun 19, 2019 at 02:18 AM
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.


System Configuration: Windows 7,
MS Office 2007

5 responses

RWomanizer Posts 365 Registration date Monday February 7, 2011 Status Contributor Last seen September 30, 2013 120
Apr 15, 2011 at 04:15 AM
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
3
gteymurova Posts 1 Registration date Thursday June 18, 2015 Status Member 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
0
I was requested to come up with a system for sending birthday messages in outlook and my search is over thanks to you.
0
Dear Rahul,

Please elaborate the steps also, how to use this code.

Thanks
0
Blocked Profile > Sidami_5147
Jun 18, 2019 at 07:45 AM
If you were to continue to read the thread, you would find the deployment instructions in posts following the one you commented on. Please understand, this is closed solved, so if you have more questions, it is important that you open your own thread, and reference this one.
0
bkdroid13 Posts 11 Registration date Wednesday May 29, 2019 Status Member Last seen October 5, 2019 1
Jun 19, 2019 at 02:18 AM
Genious !! Its great post and help me a lot. please keep continue posting
0