跳到主要內容

如何在Outlook日曆上按生日計算和顯示年齡?

一般來說,聯繫人的生日會自動添加為日曆中的年度定期約會。 但是您知道如何計算聯繫人的年齡並直接在日曆視圖中顯示該年齡嗎? 本文將介紹一個VBA,以計算每個聯繫人的年齡,並在Outlook中顯示相對定期約會主題的年齡。

在Outlook日曆上按生日計算並顯示年齡

Office 標籤 - 在 Microsoft Office 中啟用選項卡式編輯和瀏覽,讓工作變得輕而易舉
Kutools for Outlook - 透過 100 多個進階功能增強 Outlook,實現卓越效率
使用這些進階功能增強您的 Outlook 2021 - 2010 或 Outlook 365。 享受全面的 60 天免費試用並提升您的電子郵件體驗!

箭頭藍色右氣泡在Outlook日曆上按生日計算並顯示年齡

若要計算每個聯繫人的年齡並在Outlook日曆中顯示相對重複約會主題中的年齡,請執行以下操作:

1。 打開默認的日曆文件夾,然後按 其他 + F11 鍵以打開“ Microsoft Visual Basic應用程序”窗口。

2。 點擊 插入 > 模塊,然後將以下VBA代碼粘貼到新的模塊窗口中。

VBA:在Outlook日曆中計算並顯示聯繫人的年齡

Option Explicit
Public Sub UpdateAges()
Dim xOlApp As Outlook.Application
Dim xOlFolder As Outlook.Folder
Dim xOlItems As Outlook.Items
Dim xAppointmentItem As AppointmentItem
Dim xAge As Integer
Dim xOlProp As Outlook.UserProperty
Set xOlApp = Outlook.Application
Set xOlFolder = Session.GetDefaultFolder(olFolderCalendar)
Set xOlItems = xOlFolder.Items
For Each xAppointmentItem In xOlItems
If (InStr(1, xAppointmentItem.Subject, "Birthday") Or InStr(1, xAppointmentItem.Subject, "Anniversary")) And xAppointmentItem.IsRecurring = True Then
With xAppointmentItem
If xAppointmentItem.UserProperties("Original Subject") Is Nothing Then
Set xOlProp = xAppointmentItem.UserProperties.Add("Original Subject", olText, True)
xOlProp.Value = .Subject
.Save
End If
xAge = DateDiff("yyyy", .Start, Date)
.Subject = .UserProperties("Original Subject") & " (" & xAge & " in " & Format(Date, "yyyy") & ")"
.Save
End With
End If
Next
Set xAppointmentItem = Nothing
Set xOlItems = Nothing
Set xOlFolder = Nothing
Set xOlApp = Nothing
End Sub

3。 按 F5 鍵或 按鈕以運行此VBA。

當您返回默認日曆時,您會看到每個聯繫人的年齡都已確定並顯示在定期生日約會的主題中。 看截圖:

筆記:
(1)對於某位聯繫人的定期生日約會,該聯繫人的年齡用類似以下的括號括起來 (41中的2017), 41 是年齡,並且 2017 是當前年份。
(2)如果您在聯繫人文件夾中更改某個聯繫人的生日,則年齡將從日曆中自動刪除。
(3)此VBA僅適用於默認的Outlook日曆。


箭頭藍色右氣泡相關文章


最佳辦公生產力工具

Kutools for Outlook - 超過 100 種強大的功能可增強您的 Outlook

🤖 人工智慧郵件助手: 具備人工智慧魔力的即時專業電子郵件——一鍵天才回覆、完美語調、多語言掌握。輕鬆改變電子郵件! ……

📧 電子郵件自動化: 外出(適用於 POP 和 IMAP)  /  安排發送電子郵件  /  發送電子郵件時按規則自動抄送/密件副本  /  自動轉送(進階規則)   /  自動添加問候語   /  自動將多收件者電子郵件拆分為單獨的訊息 ...

📨 電子郵件管理: 輕鬆回憶電子郵件  /  按主題和其他人阻止詐騙電子郵件  /  刪除重複的電子郵件  /  進階搜索  /  合併資料夾 ...

📁 附件專業版批量保存  /  批量分離  /  批量壓縮  /  自動保存   /  自動分離  /  自動壓縮 ...

🌟 介面魔法: 😊更多又漂亮又酷的表情符號   /  使用選項卡式視圖提高 Outlook 工作效率  /  最小化 Outlook 而不是關閉 ...

👍 一鍵奇蹟: 使用傳入附件回覆全部  /   反網路釣魚電子郵件  /  🕘顯示寄件者的時區 ...

👩🏼‍🤝‍👩🏻 通訊錄和行事曆: 從選定的電子郵件中大量新增聯絡人  /  將聯絡人群組拆分為各組  /  刪除生日提醒 ...

超過 100特點 等待您的探索! 按此處了解更多。

閱讀更多       免費下載      購買
 

 

Comments (3)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
MsgBox "Fertig!" & vbCrLf & Zaehler & " Geburtstagseinträge geändert.", vbInformation, "Geburtstage angepasst "

Could you please translate this line for me? TIA
This comment was minimized by the moderator on the site
If possible, could you please give the above directive for auto-count in English??

Danke
This comment was minimized by the moderator on the site
Is there a way to set this up without using the birthday feature of the contact card?

On recurring could you set this up to show the number of years?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations