• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Add the Age to a Birthday on Outlook's Calendar

Slipstick Systems

› Developer › Code Samples › Add the Age to a Birthday on Outlook’s Calendar

Last reviewed on September 12, 2014     8 Comments

Years on next event

I'm often asked how to include a person's age on the birthday event in the calendar. While it is logical that people would want to see this, its not a feature in current versions of Outlook. There are a handful of ways you can include the person's age: use a macro or use a custom contact or appointment form to calculate their age. (I have a contact form example here and an appointment form here.)

The custom appointment form is an interesting concept but the form doesn't update automatically, so the age is less likely to be correct. It also shows the current age on all occurrences, not the age for that year. (That is a problem with this macro too, unfortunately.)

Instead of using a form, we can use a macro to calculate a person's age (and anniversary years) and add it to the subject field, in the form of Full Name's Birthday (27 in 2014). To make it easier to construct the subject in future years, the macro writes the original subject to a custom field and uses that value in the new subject.

The age is calculated by subtracting the birth year from the current year. This requires users to run the macro just once per year. It would be possible to get the date difference, but you'd need to run it frequently (weekly or monthly). While this is possible using a task reminder and another macro, identifying the age as 'this year' should meet the needs of many users.

Option Explicit
Public Sub UpdateAges()
Dim objOL As Outlook.Application
Dim objOutlookItem As Object
Dim objItems As Outlook.Items
Dim objFolder As Outlook.Folder
Dim obj As AppointmentItem
Dim Age As Integer
Dim objProp As Outlook.UserProperty
  
Set objOL = Outlook.Application
Set objFolder = Session.GetDefaultFolder(olFolderCalendar)
Set objItems = objFolder.Items
  
For Each obj In objItems
    
If (InStr(1, obj.Subject, "Birthday") Or InStr(1, obj.Subject, "Anniversary")) And obj.IsRecurring = True Then
  
  With obj
 ' see if the custom field exists, if not create it
    If obj.UserProperties("Original Subject") Is Nothing Then
        Set objProp = obj.UserProperties.Add("Original Subject", olText, True)
        objProp.Value = .Subject
        .Save
    End If
' can use a specific date instead of 'today' (Date)
 ' Age = DateDiff("yyyy", .Start, "1/1/2015")
   Age = DateDiff("yyyy", .Start, Date)
    
    .Subject = .UserProperties("Original Subject") & " (" & Age & " in " & Format(Date, "yyyy") & ")"
    .Save
  End With
    
End If
 
Next
  
Set obj = Nothing
Set objOutlookItem = Nothing
Set objItems = Nothing
Set objFolder = Nothing
Set objOL = Nothing
End Sub

Calculate the age in years and months

Age in years and months

While I think the age reached during the birthday "this year" makes the most sense, if you want to display the age as of "this month" you can do that by replacing a couple of lines in the code above to calculate the age. The subject line in the event would use a format such as Full Name's Birthday (26 years 9 months in Sep 2014).

To do this, you'll need to calculate the date difference and determine if the birthday has occurred yet this year. If not, subtract 1 from the years and calculate the remaining months.

You'll need to run the macro on a regular basis and can set up a task to trigger the macro when a reminder fires. Instructions are below.

Replace the Age and .subject lines (2 lines) in the macro above with the following.

    Dim M As Integer
    Dim strAge as String
    Age = DateDiff("yyyy", .Start, Date)
    M = Month(Date) - Month(.Start)
    ' see if birthday is coming up
    If M < 0 Then
        Age = Age - 1
        M = 12 + M
    End If

' only use months if not 0. 
    If M = 0 Then
      strAge = Age & " years"
    Else
      strAge = Age & " years " & M & " months"
    End If
    .Subject = .UserProperties("Original Subject") & " (" & strAge & " in " & Format(Date, "mmm yyyy") & ")"

Run macro using a Task Reminder

You can run the macro when a task reminder fires by adding this code to ThisOutlookSession and creating a recurring task with the category "Update Ages". When the reminder fires, the macro runs to update the ages.

Do something when a Task reminder fires for more information.

Private Sub Application_Reminder(ByVal Item As Object)
If Item.MessageClass <> "IPM.Task" Then
  Exit Sub
End If
 
If Item.Categories <> "Update Ages" Then
  Exit Sub
End If
 
Call UpdateAges
End Sub

How to use macros

First: You will need macro security set to low during testing.

To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

More information as well as screenshots are at How to use the VBA Editor

Add the Age to a Birthday on Outlook's Calendar was last modified: September 12th, 2014 by Diane Poremsky

Related Posts:

  • Create a deferred Birthday message for an Outlook Contact
  • To calculate the age of an Outlook contact
  • Create Outlook appointments using multiple recurring patterns
  • Create Birthday Events for Public Folder Contacts

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
8 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Rick Sable
January 19, 2021 9:44 am

Aniversaries seem not to work for me, any ideas what I can check??

0
0
Reply
M Johnson
January 31, 2017 3:58 pm

Hi Diane! When I run the first macro you list above, I receive "runtime error '13' Type Mismatch. When I hit debug, it jumps down to Next. Can you help? Thank you!

0
0
Reply
Diane Poremsky
Author
Reply to  M Johnson
May 25, 2017 8:24 pm

Sorry I missed this comment. It should be running on the default calendar, so its not that you have the wrong folder selected. I wonder if there is something that is not an appointment item... try changing this:
Dim obj As AppointmentItem
to
Dim obj As object

0
0
Reply
M Johnson
Reply to  Diane Poremsky
May 23, 2018 11:30 am

Thank you! That worked. Is there also a way to run this on a shared calendar, not just the default?

0
0
Reply
Diane Poremsky
Author
Reply to  M Johnson
May 23, 2018 1:18 pm

This line sets the folder:
Set objFolder = Session.GetDefaultFolder(olFolderCalendar)
you can change it to a shared folder or the current folder. Current folder is easier:
Set objFolder = Application.ActiveExplorer.CurrentFolder

More information is here - https://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/

0
0
Reply
M Johnson
January 17, 2017 3:58 pm

I am receiving a runtime '13 error with type mismatch. Any suggestions?

1
0
Reply
Alpha McPherson
October 21, 2014 9:44 pm

I cut and paste the code to add age of birthday for the year, however, It only works sporadically. Only one or two ages display out of maybe five of six per month. I used Office 365 outlook 2013 in Win 8.1 Pro 64 bit. Need recommendation.

1
0
Reply
Diane Poremsky
Reply to  Alpha McPherson
October 22, 2014 12:07 am

The code looks at these properties - subject contains the word 'Birthday' or 'Anniversary' (it's case sensitive) and the item is recurring.

Do the birthday events have Birthday, with a capital B, in the subject? If some use lower case, use lcase to convert all subjects to lower case and use lowercase 'birthday' in the statement.
If (InStr(1, lcase(obj.Subject), "birthday") Or InStr(1, lcase(obj.Subject), "anniversary")) And obj.IsRecurring = True Then

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 30 Issue 32

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Jetpack plugin with Stats module needs to be enabled.
  • Move Deleted Items to Another Folder Automatically
  • Buttons in the New Message Notifications
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Move Deleted Items to Another Folder Automatically

Buttons in the New Message Notifications

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

:wpds_smile::wpds_grin::wpds_wink::wpds_mrgreen::wpds_neutral::wpds_twisted::wpds_arrow::wpds_shock::wpds_unamused::wpds_cool::wpds_evil::wpds_oops::wpds_razz::wpds_roll::wpds_cry::wpds_eek::wpds_lol::wpds_mad::wpds_sad::wpds_exclamation::wpds_question::wpds_idea::wpds_hmm::wpds_beg::wpds_whew::wpds_chuckle::wpds_silly::wpds_envy::wpds_shutmouth:
wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment