Access Get subfolder of shared folder meetings

有些话、适合烂在心里 提交于 2020-07-22 03:44:24

问题


I have the code below that should let me retrieve the meetings from a shared sub calendar, but it doesn't work.

If I only try to access the main shared calendar it works perfect, but not for the sub calendars..

could someone point me to the right way?

Public Sub getCalendarData(calendar_name As String, sDate As Date, eDate As Date, Optional recurItem As Boolean = True)
    On Error GoTo ErrorHandler

    Dim oOL As Outlook.Application
    Dim oNS As Outlook.Folder
    Dim oAppointments As Outlook.AppointmentItem
    Dim oAppointmentItem As Outlook.AppointmentItem
    Dim strFilter As String
    Dim ItemsCal As Outlook.Items
    Dim olFolder As Outlook.Folder
    Dim fldCalendar As Outlook.Folder
    Dim iCalendar As Integer
    Dim nmsNameSpace As Outlook.Namespace
    Dim objDummy As Outlook.MailItem
    Dim objRecip As Outlook.Recipient

    'Set objects

    Set oOL = CreateObject("Outlook.Application")
    Set nmsNameSpace = oOL.GetNamespace("MAPI")

    Set objDummy = oOL.CreateItem(olMailItem)

    Set objRecip = nmsNameSpace.CreateRecipient("shared calendar name")
    objRecip.Resolve

    'Set filter to grab items by date range
    strFilter = "[Start] >= " _
    & "'" & sDate & "'" _
    & " AND [End] <= " _
    & "'" & eDate & "'"

    With ItemsCal
        .Sort "[Start]"
        .IncludeRecurrences = recurItem
    End With

    If objRecip.Resolved Then
        On Error Resume Next
        Set fldCalendar = nmsNameSpace.GetSharedDefaultFolder(objRecip, olFolderCalendar).Folders("sub_calendar_name")

        If Not fldCalendar Is Nothing Then
            Set ItemsCal = fldCalendar.Items
            If Not ItemsCal Is Nothing Then
                For Each oAppointmentItem In ItemsCal.Restrict(strFilter)
                    Set objItem = oAppointmentItem
                    With oAppointmentItem
                        iCalendar = getSegmentIDByName(calendar_name)
                        meeting_id = insertAppointment(iCalendar, .Start, .End, scrubData(.Subject), scrubData(.Location), Format(.Start, "Long Time"), .duration, .Body)
                        Call GetAttendeeList(meeting_id, objItem, .Recipients)
                    End With
                Next
            End If
        End If
    End If

    'Garbage cleanup
    Set oAppointmentItem = Nothing
    Set oAppoinments = Nothing
    Set oNS = Nothing
    Set oOL = Nothing

Exit Sub
ErrorHandler:
    'MsgBox "Error: " & Err & " | " & Error(Err)
    'Whenever error occurs, skip to next
    Resume Next
End Sub

The problem is that fldCalendar is always returning nothing and I don't know what is wrong..

Thank you!


回答1:


Keep in mind that in the cached mode when you are accessing a default folder from another mailbox, you are not accessing the whole mailbox - the folder (but not its subfolders) is cached in your primary OST file.

You can add the whole mailbox as a delegate store (Advanced tab of the Exchange account properties dialog box) and then drill down to that folder from Store.RootFolder (where Store is retrieved from the Namespace.Stores collection).

If using Redemption is an option, is version of RDOSession.GetSharedDefaultFolder (or RDOSession.GetSharedMailbox) returns a live folder (RDOFolder), not its cached version, so you will be able to access the subfolders.



来源:https://stackoverflow.com/questions/39199461/access-get-subfolder-of-shared-folder-meetings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!