2017-12-21 4 views
0

이번 달 5 일에서 다음 달 4 일 사이에 발생하는 일정에있는 모든 약속을 얻으려고합니다 (해당 날짜에 발생하는 약속 포함).항목 Outlook 일정 (VBA)의 약속 약속

Private Sub Application_Startup() 

    Dim oOL As New Outlook.Application 
    Dim oNS As Outlook.NameSpace 
    Dim oAppointments As Object 
    Dim monthlyPats As Object 
    Dim oAppointmentItem As Outlook.AppointmentItem 

    'Set up date filter 
    Dim sMth As Date 
    Dim eMth As Date 

    sMth = dhFirstDayInMonth() + 3 '4th of this month 
    eMth = dhLastDayInMonth() + 4 '4th of next month 

    Dim eDate As String 
    eDate = "[End] < '" & eMth & "'" 

    Dim sDate As String 
    sDate = "[Start] > '" & sMth & "'" 

    'Restrict tasks based on date filters 
    Set oNS = oOL.GetNamespace("MAPI") 
    Set oAppointments = Session.GetDefaultFolder(olFolderCalendar).Folders("Portfolio analysis scheduler").Items.Restrict(eDate) 
    Set monthlyPats = oAppointments.Restrict(sDate) 

End Sub 

dhFirstDayInMonth()와 dhLastDayInMonth() 함수는 단순히 현재 월의 첫 번째와 마지막 날을 얻을 : 여기

는 코드입니다.

나는 2018 년 1 월 4 일에 두 개의 이벤트가 있습니다. 하나는 종일 지속되는 반복 이벤트이고 다른 하나는 하루 종일 지속되는 독립 이벤트입니다.

불행히도, 반복되는 이벤트 만 통과합니다. 둘 다 재발 성한다면, 둘 다 내가 원하는 걸 매달 Pats에 잡히게됩니다.

누구나 설명 할 수 있고이 문제에 대한 해결책을 제시 할 수 있습니까?

답변

0

outlook의 제한 항목이 악몽 일 수 있다는 것을 알았습니다. IncludeRecurrences 속성이 True로 설정되고 시작 날짜별로 정렬되어 있는지 확인했습니다.이 트릭을 수행 한 것으로 보입니다.

또한, 나는 제한 문자열이 어떻게 한 번에 모두 작업, 좀 더 강력한 것으로 보인다 만든 :

Private Sub Application_Startup() 

    Dim oOL As New Outlook.Application 
    Dim oNS As Outlook.NameSpace 
    Dim allAppointments As Object 
    Dim oAppointments As Object 
    Dim monthlyPats As Object 
    Dim oAppointmentItem As Outlook.AppointmentItem 

    'Set up date filter 
    Dim sMth As Date 
    Dim eMth As Date 

    sMth = dhFirstDayInMonth() + 3 '4th of this month 
    eMth = dhLastDayInMonth() + 5 '5th of next month 

    Dim rstDate As String 
    rstDate = "[Start] > '" & sMth & "'" & " AND " & "[End] < '" & eMth & "'" 

    'Restrict tasks based on date filters 
    Set oNS = oOL.GetNamespace("MAPI") 
    Set allAppointments = Session.GetDefaultFolder(olFolderCalendar).Folders("Portfolio analysis scheduler").Items 
    allAppointments.IncludeRecurrences = True 
    allAppointments.Sort "[Start]" 

    Set monthlyPats = allAppointments.Restrict(rstDate) 
    monthlyPats.IncludeRecurrences = True 

End Sub