Database and Customer Relationship Management with Excel VBA Video 2

In this video we describe how to send out birthday greeting automatically using Outlook:

Private Sub cmdBirthdays_Click()
Dim myApp As Outlook.Application, myMail As Outlook.MailItem
Dim LDay As Integer, M As Integer
Dim x As Long
lastrow = Sheets(“Main Database”).Cells(Rows.count, 1).End(xlUp).Row
For x = 2 To lastrow
LDay = Day(Cells(x, 6).Value)
DDay = Day(Date)

If LDay = DDay And Cells(x, 6).Value <> “” And Month(Cells(x, 6).Value) = Month(Date) Then
Set myApp = New Outlook.Application
Set myMail = myApp.CreateItem(olMailItem)
myMail.To = Cells(x, 5).Value

With myMail
.Subject = “Happy Birthday!”
.Body = “Many happy returns of the day.” & vbCrLf & “Clare Smith”
End With

Cells(x, 7) = “yes”
Cells(x, 7).Interior.ColorIndex = 3
Cells(x, 7).Font.ColorIndex = 2
Cells(x, 7).Font.Bold = True
End If
Set myApp = Nothing
Set myMail = Nothing
End Sub

Watch the training video below:

View video on YouTube

Download a sample file by clicking on the Excel icon: