Skip to main content

如何將生日從 Excel 匯入到 Outlook 日曆?

Author: Xiaoyang Last Modified: 2025-05-12

如果您在工作表中有一長串的生日資訊,現在您想將這些生日作為事件匯入到您的 Outlook 日曆中。該如何使用一些快速的方法來處理這個任務呢?


使用 VBA 程式碼將生日從 Excel 匯入到 Outlook 日曆

通常,沒有直接的方法可以將生日匯入到 Outlook 日曆中。因此,我將創建一個 VBA 程式碼來解決這個問題,請按照以下步驟操作:

1. 打開包含要匯入到 Outlook 的生日的工作表,然後按住 ALT + F11 鍵以打開 Microsoft Visual Basic for Applications 視窗。

2. 點擊 插入 > 模組,然後將以下程式碼粘貼到模組視窗中。

VBA 程式碼:將生日匯入到 Outlook 日曆

Sub ImportBirthdaysToCalendar()
'Updateby ExtendOffice
Dim xWs As Excel.Worksheet
Dim xRng As Range
Dim xOlApp As Outlook.Application
Dim xCalendarFld As Outlook.Folder
Dim xAppointmentItem As Outlook.AppointmentItem
Dim xRecurrencePattern As Outlook.RecurrencePattern
Dim xRow As Integer
On Error Resume Next
Set xWs = ThisWorkbook.ActiveSheet
Set xRng = Application.InputBox("Please select the data range (only two columns):", "Kutools for Excel", , , , , , 8)
If xRng Is Nothing Then Exit Sub
If xRng.Columns.Count <> 2 Then
  MsgBox "You can only select two columns", vbOKOnly + vbCritical, "Kutools for Excel"
  Exit Sub
End If
Set xOlApp = CreateObject("Outlook.Application")
Set xCalendarFld = xOlApp.Session.GetDefaultFolder(olFolderCalendar)
For xRow = 1 To xRng.Rows.Count
  Set xAppointmentItem = xCalendarFld.Items.Add("IPM.Appointment")
  With xAppointmentItem
    .Subject = xRng.Cells(xRow, 1) & Chr(39) & "s Birthday"
    .AllDayEvent = True
    .Start = xRng.Cells(xRow, 2)
    Set xRecurrencePattern = .GetRecurrencePattern
    xRecurrencePattern.RecurrenceType = olRecursYearly
    .Save
  End With
Next
Set xWs = Nothing
Set xCalendarFld = Nothing
Set xOlApp = Nothing
End Sub

3. 仍在 Microsoft Visual Basic for Applications 視窗中,點擊 工具 > 參考資料。在彈出的「參考資料 – VBAProject」對話框中,勾選 「可用的參考資料」列表框中的 Microsoft Outlook 16.0 Object Library 選項,參見截圖:

doc-import-birthday-to-calendar-1

4. 然後點擊 確定 關閉此對話框。現在,按下 F5 鍵運行程式碼,會彈出一個提示框,請選擇姓名和生日欄位,參見截圖:

doc-import-birthday-to-calendar-2

5. 接著,點擊 確定 按鈕,生日將立即被匯入到 Outlook 日曆中,您可以啟動您的 Outlook 查看結果,參見截圖:

doc-import-birthday-to-calendar-3

Outlook中的AI郵件助理:更聰明的回覆,更清晰的溝通(一鍵奇蹟!) 免費

使用Kutools for Outlook的AI郵件助理簡化您的日常Outlook任務。這個強大的工具會從您過去的郵件中學習,提供智能且準確的答覆,優化您的郵件內容,並幫助您輕鬆起草和潤色郵件。
doc ai email handle

此功能支援:

  • 智能回覆:根據您過去的對話獲得量身定制、精確且隨時可用的回覆。
  • 增強內容:自動優化您的郵件文字以提高清晰度和影響力。
  • 輕鬆撰寫:只需提供關鍵字,讓AI處理其餘部分,並有多種寫作風格可供選擇。
  • 智能擴展:通過上下文感知建議來拓展您的思路。
  • 摘要生成:即時獲取長郵件的簡潔概述。
  • 全球觸及:輕鬆將您的郵件翻譯成任何語言。

此功能支援:

  • 智能郵件回覆
  • 優化的內容
  • 基於關鍵字的草稿
  • 智能內容擴展
  • 郵件摘要生成
  • 多語言翻譯

最重要的是,此功能永遠完全免費不要再等待了——立即下載AI郵件助理並享受吧