VBOffice

Sort Contacts by Birthday

This script creates a birthday list correctly sorted by day and month, and ignoring the year of birth.

Last modified: 2013/02/01 | Accessed: 36.103  | #96
◀ Previous sample Next sample ▶
SAM SAM
Determine the "identity" of your emails. Set with SAM the sender and the folder folder for sent items with the help of rules.

Contacts in Outlook cannot be usefully sorted by birthday because the year isn't ignored. However, for birthdays only the day and the month are of interest.

This VBA procedure adds a new field to a contact folder of your choice, and copies the day and the month of the contact's birthday to it. For getting it sorted right, the format must be 'mm/dd.', that is the month first, then the day.


tip  How to add macros to Outlook
Public Sub AddFormattedBirthday()
  Dim Folder As Outlook.MAPIFolder
  Dim Items As Outlook.Items
  Dim UserProps As Outlook.UserProperties
  Dim Prop As Outlook.UserProperty
  Dim obj As Object
  Dim Contact As Outlook.ContactItem
  Dim BDay As Date
  Dim DateFormat$
  Dim Name$

  'Name of the new field
  Name = "FormattedBirthday"

  'Date format.
  DateFormat = "mm.dd."

  While Folder Is Nothing
    Set Folder = Application.Session.PickFolder
    If Folder Is Nothing Then Exit Sub
    If Folder.DefaultItemType <> olContactItem Then
      MsgBox "Select a contact folder", vbInformation
      Set Folder = Nothing
    End If
  Wend

  Set Items = Folder.Items
  If Items.Count Then
    For Each obj In Items
      If TypeOf obj Is Outlook.ContactItem Then
        Set Contact = obj
        BDay = Contact.Birthday
        If Year(BDay) > 0 And Year(BDay) < 4000 Then
          Set UserProps = Contact.UserProperties
          Set Prop = UserProps.Item(Name)
          If Prop Is Nothing Then
            Set Prop = UserProps.Add(Name, olText, True)
          End If
          Prop.Value = Format(BDay, DateFormat)
          Contact.Save
        End If
      End If
    Next
  End If
End Sub

Category-Manager Category-Manager
With Category-Manager you can group your Outlook categories, share them with other users, filter a folder by category, automatically categorize new emails, and more. You can use the Addin even for IMAP.
email  Send a message