Outlook 2010 Select Calendar

2019-09-10 06:03发布

问题:

I have some users who would like to have multiple calendars selected when they switch to calendar folder in theirs Outlook. So I took a sample code from:

http://www.slipstick.com/developer/code-samples/select-multiple-calendars-outlook/

Modified it a little and gave to my users. Problem is that it is not working on one of these Outlooks and I cannot find out why. Below is my code and the exact problem is that this macro cannot "select/enable" the calendar I want - but if I try to debug the code and put MsgBox for testing - looks like the code is in right place. Procmon is not showing any "access denied" or other kind of errors. Could You help me to investigate this ?

    Sub SelectCalendars()
    Dim objPane As Outlook.NavigationPane
    Dim objModule As Outlook.CalendarModule
    Dim objGroupA, objGroupB As Outlook.NavigationGroup
    Dim objNavFolder As Outlook.NavigationFolder
    Dim objCalendar As Folder
    Dim objFolder As Folder
    Dim i As Integer
    Dim test As Outlook.NavigationFolder


    Set Application.ActiveExplorer.CurrentFolder = Session.GetDefaultFolder(olFolderCalendar)
    DoEvents

    Set objCalendar = Session.GetDefaultFolder(olFolderCalendar)
    Set objPane = Application.ActiveExplorer.NavigationPane
    Set objModule = objPane.Modules.GetNavigationModule(olModuleCalendar)


    With objModule.NavigationGroups
        Set objGroupA = .Item(1)
    End With

    ' First calendar group
    Set objNavFolder = objGroupA.NavigationFolders.Item(1)
    MsgBox objNavFolder.DisplayName
    MsgBox objNavFolder.IsSelected
    objNavFolder.IsSelected = False

   ' Second calendar group
    Set objNavFolder = objGroupA.NavigationFolders.Item(2)
    MsgBox objNavFolder.DisplayName
    MsgBox objNavFolder.IsSelected
    objNavFolder.IsSelected = False


    Set objPane = Nothing
    Set objModule = Nothing
    Set objGroup = Nothing
    Set objNavFolder = Nothing
    Set objCalendar = Nothing
    Set objFolder = Nothing
End Sub

回答1:

First of all, I'd suggest using the Debug.Print statements instead of Message boxes.

The IsSelected property of the NavigationFolder class allows to set a boolean variable that indicates whether the NavigationFolder object is selected for display. Try to set this property to true (instead of false).