跳至主要内容

如何从Excel电子表格创建Outlook提醒?

Author: Siluvia Last Modified: 2025-05-07

本文讨论如何根据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