Skip to main content

如何從 Excel 試算表建立 Outlook 提醒?

Author: Siluvia Last Modified: 2025-05-12

本文將介紹如何根據 Excel 試算表中的數據建立 Outlook 提醒。

使用 VBA 程式碼從 Excel 試算表建立 Outlook 提醒


使用 VBA 程式碼從 Excel 試算表建立 Outlook 提醒

如果您想從 Excel 建立 Outlook 提醒,請按照以下步驟操作。

1. 創建一個包含欄位標題和對應提醒欄位的工作表,如下方截圖所示。

steps of using vba to create Outlook reminders from Excel spreadsheet

注意:對於「忙碌狀態」欄,數字「2」表示提醒將在您的 Outlook 日曆中顯示為「忙」。您可以根據需要將其更改為「1(暫定)」、「3(外出)」、「4(在其他地方工作)」或「5(免費)」。

2. 按下「Alt」+「F11」鍵以打開「Microsoft Visual Basic for Applications」視窗。

3. 在「Microsoft Visual Basic for Applications」視窗中,點擊「插入」>「模組」。然後將以下 VBA 程式碼複製到程式碼視窗中。

VBA 程式碼:從 Excel 試算表建立 Outlook 提醒

Sub AddAppointments()
'Update by Extendoffice 20180608
    Dim I As Long
    Dim xRg As Range
    Dim xOutApp As Object
    Dim xOutItem As Object
    Set xOutApp = CreateObject("Outlook.Application")
    Set xRg = Range("A2:G2")
    For I = 1 To xRg.Rows.Count
        Set xOutItem = xOutApp.CreateItem(1)
        Debug.Print xRg.Cells(I, 1).Value
        xOutItem.Subject = xRg.Cells(I, 1).Value
        xOutItem.Location = xRg.Cells(I, 2).Value
        xOutItem.Start = xRg.Cells(I, 3).Value
        xOutItem.Duration = xRg.Cells(I, 4).Value
        If Trim(xRg.Cells(I, 5).Value) = "" Then
            xOutItem.BusyStatus = 2
        Else
            xOutItem.BusyStatus = xRg.Cells(I, 5).Value
        End If
        If xRg.Cells(I, 6).Value > 0 Then
            xOutItem.ReminderSet = True
            xOutItem.ReminderMinutesBeforeStart = xRg.Cells(I, 6).Value
        Else
            xOutItem.ReminderSet = False
        End If
        xOutItem.Body = xRg.Cells(I, 7).Value
        xOutItem.Save
        Set xOutItem = Nothing
    Next
    Set xOutApp = Nothing
End Sub

注意:在上述程式碼中,「A2:G2」是您要基於建立約會的數據範圍。

4. 按下「F5」或點擊「執行」按鈕來運行程式碼。然後所有帶有特定欄位的約會將立即插入到您的 Outlook 日曆中。

接著,您可以前往 Outlook 的日曆檢視結果。請參閱截圖:

steps of using vba to create Outlook reminders from Excel spreadsheet