使用VBA从Excel数据中创建Outlook约会



标题说明了一切。我昨天写了代码,效果很好。我是个白痴,保存不正确,丢失了代码。但是,今天我重写了代码以实现它,我不确定为什么今天没有创建约会。当我通过我的子f8时,将正确存储这些值。如果有人可以指出我忽略的一个希望的愚蠢错误,那将是一个救生员,因为我自己找不到它。

Sub test()
    Dim OL As Outlook.Application, Appoint As Outlook.AppointmentItem, ES As Worksheet, _
    r As Long, i As Long, WB As ThisWorkbook
    Set WB = ThisWorkbook
    Set ES = WB.Sheets("Export Sheet")
    r = ES.Cells(Rows.count, 1).End(xlUp).Row
    Set OL = New Outlook.Application
    For i = 2 To r
        Set Appoint = OL.CreateItem(olAppointmentItem)
        With Appoint
            .Subject = ES.Cells(i, 1).Value
            .Start = ES.Cells(i, 2).Value
            .End = ES.Cells(i, 3).Value
            .Location = ES.Cells(i, 4).Value
            .AllDayEvent = ES.Cells(i, 5).Value
            .Categories = ES.Cells(i, 6).Value & " Category"
        End With
    Next i
    Set OL = Nothing
End Sub

这里有一个工作示例

看起来您从循环末端缺少.Save

这样:

For i = 2 To r
    Set Appoint = OL.CreateItem(olAppointmentItem)
    With Appoint
        .Subject = ES.Cells(i, 1).Value
        .Start = ES.Cells(i, 2).Value
        .End = ES.Cells(i, 3).Value
        .Location = ES.Cells(i, 4).Value
        .AllDayEvent = ES.Cells(i, 5).Value
        .Categories = ES.Cells(i, 6).Value & " Category"
        .Save
    End With
Next i

相关内容

  • 没有找到相关文章

最新更新