Outlook:予定表の切り替え

Google CalenderのデータをOutlookに取り込んだ後に印刷を行うという運用を想定。
毎回フィルタするのが面倒なので、自動化。

Sub auto_enabler_calender()
    Dim myCal As String
    Dim navModCal As CalendarModule
    
    myCal = "Google"
    
    Dim ContactsFolder As Folder
    Set ContactsFolder = Session.GetDefaultFolder(olFolderCalendar)
    Session.SendAndReceive (True)
    ContactsFolder.Display

    Set navModCal = ActiveExplorer.NavigationPane.Modules.GetNavigationModule(olModuleCalendar)
    'show myCal calender
    For Each navGroup In navModCal.NavigationGroups
        For Each navFolder In navGroup.NavigationFolders
            Debug.Print navFolder.DisplayName
            If navFolder.DisplayName = myCal Then
                navFolder.IsSelected = True
            End If
        Next
    Next
    'hide other calender
    For Each navGroup In navModCal.NavigationGroups
        For Each navFolder In navGroup.NavigationFolders
            Debug.Print navFolder.DisplayName
            If navFolder.DisplayName <> myCal Then
                navFolder.IsSelected = False
            End If
        Next
    Next
End Sub