Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Insert Outlook Contact Birthdays in Calendar

0.00/5 (No votes)
15 Nov 2010 1  
This macro can be inserted in Outlook 2000 to search all your contacts for birthday information. If the birthday does not appear in the calendar, then insert it. The macro will dump a small text file c:Outlook.log that lists the activity.

Open your Outlook, goto Tools -> Macro -> Visual Basic Editor


Do a right-button on ThisOutlookSession and insert a module.


Paste the code below, and run.


VB
Sub FindBirthdays()
    Dim Person As Variant
    Dim Bday As Variant
    Dim NewBday As Outlook.AppointmentItem
    Dim NewPatt As Outlook.RecurrencePattern
    
    LogFile = "c:\Outlook.log"
    fnum = FreeFile()
    Open LogFile For Output As fnum
    Print #fnum, "Outlook Birthday Export"
    
    Set olns = ThisOutlookSession.Application.GetNamespace("MAPI")
    Set ContactFolder = olns.GetDefaultFolder(olFolderContacts)
    Set CalendarFolder = olns.GetDefaultFolder(olFolderCalendar)
    Set MyContacts = ContactFolder.Items
    Set MyBirthdays = CalendarFolder.Items
    
    For Each Person In MyContacts
        If Person.Class = olContact Then
            If Year(Person.Birthday) < 4000 Then
                
                
                ' check if this birthday is on my calendar
                foundBirthday = False
                For Each Bday In MyBirthdays
                   If Bday.Class = olAppointment Then
                       If InStr(Bday.Subject, "Birthday") > 0 And _
                            Left(Bday.Subject, 5) = Left(Person.FullName, 5) Then
                        foundBirthday = True
                       End If
                   End If
                Next Bday
                If foundBirthday Then
                    Print #fnum, Person.FullName; Tab(30); _
                     Format(Person.Birthday, "dd-mmm-yyyy")
                Else
                    Set NewBday = Outlook.CreateItem(olAppointmentItem)
                    Set NewPatt = NewBday.GetRecurrencePattern
                    NewPatt.RecurrenceType = olRecursYearly
                    NewPatt.PatternStartDate = Person.Birthday
                    NewPatt.DayOfMonth = Day(Person.Birthday)
                    NewPatt.MonthOfYear = Month(Person.Birthday)
                    NewPatt.NoEndDate = True
                    NewBday.MeetingStatus = olNonMeeting
                    NewBday.Subject = Person.FullName & "'s Birthday"
                    NewBday.Start = Person.Birthday
                    NewBday.AllDayEvent = True
                    NewBday.BusyStatus = olFree
                    'NewBday.Display
                    NewBday.Save
                    Print #fnum, Person.FullName; Tab(30); _
                     Format(Person.Birthday, "dd-mmm-yyyy"); _
                     Tab(50); "Added to calendar"
                End If
            End If
        End If
    Next Person
    Close #fnum
End Sub

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here