Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

 How to send a greeting message to a contact automatically if his birthday is today in Outlook?

Sometime, you may want to send a greeting message automatically to the contact when his birthday is today in Outlook. It will be a tedious job when you check the contact’ birthday one by one and send the greeting emails manually. This article, I will introduce a VBA code to solve it quickly and easily.

Send a greeting message automatically to a contact based on his birthday with VBA code in Outlook


Send a greeting message automatically to a contact based on his birthday with VBA code in Outlook

To send a greeting message automatically to a contact if his birthday is today, insert a VBA code first, then you need to create a recurring task to trigger the code.

The following steps may help you:

1. Launch the Outlook, and then hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

2. In the Microsoft Visual Basic for Applications window, double click ThisOutlookSession from the Project1(VbaProject.OTM) pane to open the mode, and then copy and paste the following code into the blank module.

VBA code: Auto send a greeting message to a contact based on birthday:

Private Sub Application_Reminder(ByVal Item As Object)
Dim xTempMail As MailItem
Dim xFilePath As String
Dim xItems As Outlook.Items
Dim xItem As Object
Dim xContactItem As Outlook.ContactItem
Dim xTodayDate As String
Dim xBirthdayDate As String
Dim xGreetingMail As Outlook.MailItem
Dim xWordDoc As Word.Document
Dim xGreetings As String
Dim xBool As Boolean
xFilePath = CreateObject("shell.Application").NameSpace(5).self.Path & "\UserTemplates"
Set xFSO = CreateObject("Scripting.FileSystemObject")
If xFSO.FolderExists(xFilePath) = False Then
    MkDir xFilePath
End If
If IsFileExists(xFilePath & "\Birthday Greeting Mail.oft") = False Then
    Set xTempMail = Outlook.CreateItem(olMailItem)
    xTempMail.SaveAs xFilePath & "\Birthday Greeting Mail.oft", olTemplate
    xTempMail.Close olDiscard
End If
If (TypeOf Item Is TaskItem) And (Item.Subject = "Send Birthday Greeting Mail") Then
xGreetings = "Happy Birthday!"
           xGreetings = InputBox("Input birthday greetings", "Kutools for Outlook", xGreetings)
   xTodayDate = Month(Date) & "-" & Day(Date)
   Set xItems = Outlook.Application.Session.GetDefaultFolder(olFolderContacts).Items
   For Each xItem In xItems
       If Not (TypeOf xItem Is ContactItem) Then Exit Sub
       Set xContactItem = xItem
       xBirthdayDate = Month(xContactItem.Birthday) & "-" & Day(xContactItem.Birthday)
       If xBirthdayDate = xTodayDate Then
           Set xGreetingMail = Outlook.Application.CreateItemFromTemplate(xFilePath & "\Birthday Greeting Mail.oft")
           Set xWordDoc = xGreetingMail.GetInspector.WordEditor
           
           xWordDoc.Range.InsertBefore "Dear " & xContactItem.LastName & Chr(10) & xGreetings & Chr(10) & Chr(10)
           With xGreetingMail
                .Recipients.Add (xContactItem.Email1Address)
                .Subject = "Happy Birthday!"
                .Display
                .Close (olSave)
                .Send
          End With
       End If
   Next
End If
End Sub
Function IsFileExists(ByVal FileName As String) As Boolean
Dim xFileSystem As Object
Set xFileSystem = CreateObject("Scripting.FileSystemObject")
If xFileSystem.FileExists(FileName) = True Then
    IsFileExists = True
Else
    IsFileExists = False
End If
End Function 

3. Then clcik Tools > References in the Microsoft Visual Basic for Applications window, in the popped out References-Project1 dialog box, check Microsoft Word Object Library and Microsoft Scripting Runtime options from the Available References list box, see screenshot:

4. Then click OK to close the dialog, now, you should create a task to trigger the VBA code. Please go to the Task pane, click New Task to create a task:

(1.) In Subject line, you should enter Subject as Send Birthday Greeting Mail;

(2.) Then click Recurrence under the Task tab;

(3.) In the Task Recurrence dialog box, select Daily and specify every 1 day(s) option from the Recurrence pattern section;

5. Then click OK to close the dialog box, return to the task window, please set a reminder for the recurring task as following screenshot shown:

6. From now on, when the reminder alerts, the macro will be triggered immediately. A dialog box will pop out to remind you inserting the birthday greetings as following screenshot shown:

7. Then click OK button, a greeting mail will be sent to the contact whose birthday is today automatically.

 

Recommended Productivity Tools

shot kutools outlook kutools tab 1180x121
shot kutools outlook kutools plus tab 1180x121

Kutools for Outlook - More than 100 Advanced Functions for Outlook, Improve 70% Efficiency For you

  • Complicated and repeated operations can be done a one-time processing in seconds.
  • Forward multiple emails individually with one-click, and auto forward by rules.
  • Auto CC/BCC every sending email and easy for customizing rules, and auto reply without requiring exchange server.
  • Powerful junk emails filter, remove duplicate emails, reply with attachment, bunch of one-click operations, and so on...
  • 60-day unlimited free trial. 60-day money back guarantee. 2 years free upgrade and support. Buy once, use forever.
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    pedro · 7 months ago
    hay alguna forma para mac?
  • To post as a guest, your comment is unpublished.
    carlos · 8 months ago
    Buen día, podría indicar cómo el código obtiene y valida la fecha de nacimiento??? . Otra consulta es si funciona para una lista de usuarios. Es decir que valide sus fechas de nacimiento y les envíe automáticamente saludos de cumpleaños. Muchas gracias