Click here to Skip to main content
15,891,905 members
Articles / VBA
Tip/Trick

Insert Outlook Contact Birthdays in Calendar

Rate me:
Please Sign up or sign in to vote.
4.67/5 (3 votes)
15 Nov 2010CPOL 19.6K   2   3
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Systems Engineer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Sridhar Kadali28-Jun-12 0:00
Sridhar Kadali28-Jun-12 0:00 
GeneralReason for my vote of 5 Very useful tip Pin
Siedlerchr23-Nov-10 22:36
Siedlerchr23-Nov-10 22:36 
GeneralThx! Pin
Siedlerchr23-Nov-10 22:36
Siedlerchr23-Nov-10 22:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.