在特定日期之前30天创建Outlook约会

时间:2019-04-24 09:22:44

标签: excel vba outlook

我已经设置了一些代码来创建Outlook约会,尽管我尝试将开始时间设置为G列(i,7)单元格中任何日期的30天之前。

有什么办法做到这一点,还是只需要在Excel中添加此日期的附加列?

Option Explicit
Option Compare Text 'ignore case sensitivity when comparing strings

Sub EventsReminders()

    Dim OL As Outlook.Application, ES As Worksheet, _
    r As Long, i As Long, wb As ThisWorkbook

    Set wb = ThisWorkbook
    Set ES = wb.Sheets("Events")
    Set OL = New Outlook.Application

    r = ES.Cells(Rows.Count, 1).End(xlUp).Row
    For i = 8 To r
        With ES.Cells(i, 2)
            If .Value = "Yes" And ES.Cells(i, 3) <> "Yes" Then
                ES.Cells(i, 3) = "Yes"
                With OL.CreateItem(olAppointmentItem)
                    .Subject = "Raise works order"
                    .Start = ES.Cells(i, 7) + TimeValue("09:00:00")
                    .ReminderSet = True
                    .ReminderMinutesBeforeStart = 60
                    .Body = ES.Cells(i, 5).Value + "_" + ES.Cells(i, 9).Value
                    .Save
                End With
            End If
        End With
    Next i

    Set OL = Nothing
    Set wb = Nothing
    Set ES = Nothing

End Sub

1 个答案:

答案 0 :(得分:1)

假设G列包含实际日期,而不是代表日期的文本,请尝试:

.Start = ES.Cells(i, 7) - 30 + TimeValue("09:00:00")