Outlook VBA打开只读共享交换日历

时间:2017-12-12 14:08:15

标签: outlook-vba

我正在尝试使用MS Outlook 2013 VBA(MS Exchange)阅读公司会议室日历活动。我的脚本仅适用于我有写入权限的日历,但会议室共享日历是只读的。如果我在他们上面尝试我的脚本,我会得到运行时错误'-2147221233(8004010f)'。

Sub ShowOtherUserCalFolders()
    Dim namespace As Outlook.namespace
    Dim recipient As Outlook.recipient
    Dim CalendarFolder As Outlook.Folder

    Set namespace = Application.GetNamespace("MAPI")
    Set recipient = namespace.CreateRecipient("calendar-name")
    recipient.Resolve
    MsgBox recipient.Name
    'The name is shown correctly

    If recipient.Resolved Then
        Set CalendarFolder = namespace.GetSharedDefaultFolder(recipient, olFolderCalendar)
        'This should display the calendar on the screen, but it fails
        CalendarFolder.Display
        Dim oItems As Outlook.Items
        Set oItems = CalendarFolder.Items
        'The oItems is empty when trying to use read-only calendar
        MsgBox oItems.Count
    End If
End Sub

从只读共享日历获取信息的正确方法是什么?

2 个答案:

答案 0 :(得分:0)

您可以将文件夹树移动到适用的文件夹。

class CustomScrollBar(QtWidgets.QScrollBar):
    def __init__(self, *args, **kwargs):
        QtWidgets.QScrollBar.__init__(self, *args, **kwargs)
        self.baseSheet = '''
            QScrollBar {{
                width: 45px;
                margin: 45px 0 45px 0;
                background: #32CC99;
            }}

            QScrollBar::handle {{
                border: 10px solid grey;
                background: white;
                min-height: 10px;
            }}

            QScrollBar::add-line:vertical {{
                border: 2px solid grey;
                background: none;
                height: 45px;
                subcontrol-position: bottom;
                subcontrol-origin: margin;
            }}

            QScrollBar::sub-line:vertical {{
                border: 2px solid grey;
                background: none;
                height: 45px;
                subcontrol-position: top;
                subcontrol-origin: margin;
            }}

            QScrollBar::up-arrow:vertical {{
                subcontrol-position: bottom;
                subcontrol-origin: margin;
                {upArrow}
            }}

            QScrollBar::down-arrow:vertical {{
                subcontrol-position: bottom;
                subcontrol-origin: margin;
                {downArrow}
            }}

            QScrollBar::left-arrow:vertical {{
                subcontrol-position: bottom;
                subcontrol-origin: margin;
                {leftArrow}
            }}

            QScrollBar::right-arrow:vertical {{
                subcontrol-position: bottom;
                subcontrol-origin: margin;
                {rightArrow}
            }}
            '''
        self.arrowNormal = '''
                border-top: 5px solid lightgray;
                border-left: 5px solid lightgray;
                border-right: 5px solid gray;
                border-bottom: 5px solid gray;
            '''
        self.arrowPressed = '''
                border: 5px solid darkgray;
            '''
        self.setStyleSheet(self.baseSheet.format(
            upArrow=self.arrowNormal, 
            downArrow=self.arrowNormal, 
            leftArrow=self.arrowNormal, 
            rightArrow=self.arrowNormal))

    def mousePressEvent(self, event):
        QtWidgets.QScrollBar.mousePressEvent(self, event)
        opt = QtWidgets.QStyleOptionSlider()
        opt.initFrom(self)

        subControl = self.style().hitTestComplexControl(self.style().CC_ScrollBar, opt, event.pos(), self)
        if subControl == self.style().SC_ScrollBarAddLine:
            if self.orientation() == QtCore.Qt.Vertical:
                downArrow = self.arrowPressed
                upArrow = leftArrow = rightArrow = self.arrowNormal
            else:
                rightArrow = self.arrowPressed
                upArrow = downArrow = leftArrow = self.arrowNormal
        elif subControl == self.style().SC_ScrollBarSubLine:
            if self.orientation() == QtCore.Qt.Vertical:
                upArrow = self.arrowPressed
                downArrow = leftArrow = rightArrow = self.arrowNormal
            else:
                leftArrow = self.arrowPressed
                rightArrow = upArrow = downArrow = self.arrowNormal
        self.setStyleSheet(self.baseSheet.format(upArrow=upArrow, downArrow=downArrow, leftArrow=leftArrow, rightArrow=rightArrow))

    def mouseReleaseEvent(self, event):
        QtWidgets.QScrollBar.mouseReleaseEvent(self, event)
        self.setStyleSheet(self.baseSheet.format(
            upArrow=self.arrowNormal, 
            downArrow=self.arrowNormal, 
            leftArrow=self.arrowNormal, 
            rightArrow=self.arrowNormal))


class MyScrollArea(QtWidgets.QScrollArea):
    def __init__(self, parent=None):
        super(MyScrollArea, self).__init__(parent)
        w = QtWidgets.QWidget()
        w.setFixedSize(640, 480)
        self.setWidget(w)
        vScrollBar = CustomScrollBar(QtCore.Qt.Vertical)
        self.setVerticalScrollBar(vScrollBar)

答案 1 :(得分:0)

您可以使用entryID直接引用会议室。

Option Explicit

Sub ShowOtherUserCalFolders2()

    Dim CalendarFolder As Folder
    Dim oItems As items
    Dim currFolder_entryID As String

    ' Reference the boardroom directly with entryID
    '  Open the applicable calendar

    ' In the immediate pane
    ' ?ActiveExplorer.CurrentFolder.EntryID
    ' or
    Debug.Print ActiveExplorer.CurrentFolder.EntryID

    ' Once you know the entryID, hardcode and uncomment
    'currFolder_entryID = "entryID shown in the immediate pane"

    'Set CalendarFolder = Session.GetFolderFromID(currFolder_entryID)

    'Set ActiveExplorer = CalendarFolder
    'Set oItems = CalendarFolder.items
    'MsgBox "" & CalendarFolder & " has " & oItems.count & " items"

End Sub