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
Related:

5 replies

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
Ambucias Posts 47358 Registration date Monday February 1, 2010 Status Moderator Last seen September 1, 2021 11,240
Apr 15, 2011 at 04:37 AM
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
0
RWomanizer Posts 365 Registration date Monday February 7, 2011 Status Contributor Last seen September 30, 2013 120
Apr 15, 2011 at 04:49 AM
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.
0
Ambucias Posts 47358 Registration date Monday February 1, 2010 Status Moderator Last seen September 1, 2021 11,240
Apr 15, 2011 at 05:00 AM
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
0

Didn't find the answer you are looking for?

Ask a question
RWomanizer Posts 365 Registration date Monday February 7, 2011 Status Contributor Last seen September 30, 2013 120
Apr 15, 2011 at 05:03 AM
Thanks Ambucias,

I will post the same in FAQ.
0
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.
0