在VBA中连续更改一个约会

在VBA中连续更改一个约会,vba,outlook,calendar,Vba,Outlook,Calendar,如何在Outlook日历中查找一系列约会以及如何更改它 我使用以下代码查找和更改单个约会/会议 Private Sub ChangeAppointment(SearchDate As String, SearchApptSubject As String) 'SearchDate = "7/12/2017" 'SearchApptSubject = "Leave Office!" Dim oOL As New Outlook.Application

如何在Outlook日历中查找一系列约会以及如何更改它

我使用以下代码查找和更改单个约会/会议

Private Sub ChangeAppointment(SearchDate As String, SearchApptSubject As String)        

    'SearchDate = "7/12/2017"
    'SearchApptSubject = "Leave Office!"

    Dim oOL As New Outlook.Application
    Dim oNS As Outlook.NameSpace
    Dim oAppointments As Object
    Dim oAppointmentItem As Outlook.AppointmentItem
    Dim ItemDate As String
    Dim strSubject As String, strBody As String

    Set oNS = oOL.GetNamespace("MAPI")
    Set oAppointments = oNS.GetDefaultFolder(olFolderCalendar)

    For Each oAppointmentItem In oAppointments.Items

        ItemDate = Format(oAppointmentItem.Start, "mm/dd/yy")
        ItemSubject = oAppointmentItem.Subject

        If SearchDate = ItemDate And SearchApptSubject = ItemSubject Then 'Check all events on current date.

            oAppointmentItem.Start = cdate("7/12/2017 6:00 PM")
            oAppointmentItem.END = cdate("7/12/2017 6:01 PM")
            oAppointmentItem.Subject = 'Time to go home!'                
            oAppointmentItem.Save  

            Exit For

        End If

    Next

End Sub

但是,当试图查找作为系列的一部分的约会时,代码将找不到它。我想知道如何在一个系列中查找约会,以及如何仅更改该系列中的一个约会。提前谢谢

首先,您编写了调用Sort的代码,它什么都不做——您对一个从未使用过的临时对象(由编译器创建的隐式变量)调用Sort
其次,需要设置
includeCurrences
属性,并限制集合(请参阅)

dim oItems=oappoints.Items
oItems.Sort(“[Start]”)
oItems.Restrict(“[Start]>'01-01-2017'和(“[Start]<'01-07-2017'))
对于oItems中的每个oAppointmentItem
...
    dim oItems = oAppointments.Items
    oItems.Sort ("[Start]")
    oItems.Restrict("[Start] > '01-01-2017' AND ("[Start] < '01-07-2017'  ")
    For Each oAppointmentItem In oItems
      ...