Есть ли способ избежать повторяющихся встреч Outlook на VBA? - PullRequest
0 голосов
/ 09 марта 2020

Я пытаюсь написать скрипт vba, в котором он добавляет только новые встречи каждый раз, когда я добавляю новую запись в Excel. Всякий раз, когда я запускаю код во второй раз с новой записью, он добавляет дублирующую встречу в календарь. Есть ли способ добавить только новую запись, не дублируя предыдущую встречу?

Sub AddAppointments()
    ' Columns Start date(7), Columns start time(8), End time (9), reminder (10), status(11) is mostly busy(value is 2)

    ' Create the Outlook session
    Set myOutlook = CreateObject("Outlook.Application")

    ' Start at row 2
    r = 2

    Do Until Trim(Cells(r, 1).Value) = ""
        ' Create the AppointmentItem
        Set myApt = myOutlook.createitem(1)
        ' Set the appointment properties
        myApt.Subject = "Remove " + Cells(r, 1).Value
        myApt.Location = "Work drive"
        'Start time
        myApt.Start = Cells(r, 7).Value + Cells(r, 8).Value
        'Duration column
        myApt.Duration = Cells(r, 9).Value
        ' If Busy Status is not specified, default to 2 (Busy)
        If Trim(Cells(r, 11).Value) = "" Then  'Column 11 is represented the busy status(2)
            myApt.BusyStatus = 2
        Else
            myApt.BusyStatus = Cells(r, 11).Value
        End If
        If Cells(r, 10).Value > 0 Then
            myApt.ReminderSet = True
            myApt.ReminderMinutesBeforeStart = Cells(r, 10).Value 'reminder status within 30mins as noted under column 10
        Else
            myApt.ReminderSet = False
        End If
        myApt.Body = "Remove " + Cells(r, 1).Value  'pulls name from column 1
        myApt.Save
        r = r + 1
    Loop
End Sub
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...