Sometimes, you may want to count your Outlook contacts’ age. But Outlook doesn’t have this function and manually counting will be error prone. Thus this article will introduce you 2 quick approaches via Outlook VBA.
When creating new Outlook contacts, you can input the contacts’ birthdays. Then Outlook will automatically create the according recurring birthday events in your calendar. So when anyone’s birthday comes, you will receive a reminder. At this point, you must want to know the contact’s age. But Outlook doesn’t have a native feature to count the contact’s age. Fortunately, we can utilize Outlook VBA to get it with utmost ease.
Method 1: Get a Specific Outlook Contact’s Age
- To start with, launch Outlook and press “Alt + F11” key buttons.
- Then in the new “Microsoft Visual Basic for Applications” window, you ought to open a new module and copy the following VBA codes into it.
Sub CountContactAge() Dim olContact As ContactItem Dim bDay As Date Dim Age As Integer Dim strMsg As String Dim nRes As Integer Set olContact = Outlook.Application.ActiveExplorer.Selection.Item(1) If TypeName(olContact) = "ContactItem" Then If olContact.Birthday <> #1/1/4501# Then bDay = DateSerial(Year(Now), Month(olContact.Birthday), Day(olContact.Birthday)) Age = DateDiff("yyyy", olContact.Birthday, bDay) strMsg = olContact.FullName & " is " & Age & " years old now." nRes = MsgBox(strMsg, vbOKOnly + vbInformation, "Count Contact Age") Else strMsg = "You haven't input " & olContact.FullName & "'s birthday yet." nRes = MsgBox(strMsg, vbOKOnly + vbExclamation, "Count Contact Age") End If End If End Sub
- Subsequently, you can exit the current window and add the new macro to the Quick Access Toolbar as usual.
- After that, you can access your Contacts folder and select the specific contact and press the macro button in the Quick Access Toolbar.
- Finally you may get the following results:
- If you’ve not input the contact’s birthdays, you will receive an alert like the following image:
- If you’ve input the contact’s birthday, you will get a dialog box which will tell you the contact age, like the image below:
Method 1 will be tedious if you want to get several or all your contacts’ age. Thus please read on to use the Method 2.
Method 2: Quickly Get All Outlook Contacts’ Age
- At first, go to Contacts pane and hit “View Settings” button on “View” tab.
- In the new “Advanced View Settings” dialog box, hit “Columns” button.
- Then in “Show Columns” dialog box, press “New Column” button. In the “New Column” dialog, type “Age” in the “Name” box and then hit “OK”.
- After that, click a series of “OK” to back to main Outlook window.
- Subsequently, press “Alt + F11” to open “Visual Basic” window and copy the following codes into a new module.
Sub AddAgeColumn() Dim obj As Object Dim olContact As Object Dim olProp As Outlook.UserProperty Dim bDay As Date Dim Age On Error Resume Next For Each obj In Application.ActiveExplorer.Selection If TypeName(obj) = “ContactItem” And obj.Birthday <> #1/1/4501# Then Set olContact = obj bDay = DateSerial(Year(Now), Month(olContact.Birthday), Day(olContact.Birthday)) Age = DateDiff("yyyy", olContact.Birthday, bDay) Set olProp = olContact.UserProperties.Add("Age", olText, True) olProp.Value = Age olContact.Save End If Err.Clear Next End Sub
- Later you can add the new macro to the Quick Access Toolbar.
- Eventually select all the contacts by “Ctrl + A” and press the macro button in Quick Access Toolbar. You will get all the contacts’ age, except those who have no birthdays filled, like the picture below:
Beware of Risks around Your Outlook Data
Outlook is prone to corruption. Therefore, you should keep tabs on all dangers around your Outlook data. They are usually viruses, malware, power outages and human errors, etc. Moreover, so as to ensure that you can quickly repair Outlook PST data corruption, you’d better keep an experienced repair tool in vicinity, like DataNumen Outlook Repair.
Author Introduction:
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including repair corrupted SQL file and outlook repair software products. For more information visit www.datanumen.com
Leave a Reply