如何在一个Office Automation的程序中获取Shared Calendars

Imports Outlook = Microsoft.Office.Interop.Outlook

Public Class Form1
    Private OLApp As Outlook.Application
    Private OlExplorer As Outlook.Explorer
    Private OlNavigationPan As Outlook.NavigationPane
    Private CalendarModule As Outlook.CalendarModule
    Private OlNavigationGroup As Outlook.NavigationGroup

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) _
        Handles MyBase.Load
        Dim Process() As System.Diagnostics.Process = System.Diagnostics _
            .Process.GetProcessesByName("OUTLOOK")

        If Process.Length > 0 Then
            OLApp = System.Runtime.InteropServices.Marshal _
                .GetActiveObject("Outlook.Application")
        Else
            OLApp = New Outlook.Application
        End If

        If OLApp.ActiveExplorer IsNot Nothing Then
            OlExplorer = OLApp.ActiveExplorer
        Else
            OlExplorer = OLApp.Explorers.Add(OLApp.Session _
                .GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox))
            OlExplorer.Activate()
        End If

        OlNavigationPan = OlExplorer.NavigationPane
        CalendarModule = OlNavigationPan.Modules _
            .GetNavigationModule(Outlook.OlNavigationModuleType. _
                                 olModuleCalendar)

        ComboBox1.Items.Clear()

        OlNavigationGroup = CalendarModule.NavigationGroups("Shared Calendars")

        If OlNavigationGroup IsNot Nothing Then
            For Each Folder As Outlook.NavigationFolder In OlNavigationGroup _
                .NavigationFolders
                ComboBox1.Items.Add(Folder.DisplayName)
            Next
        Else
            MsgBox("OlNavigationGroup is nothing")
        End If
    End Sub

    Private Sub Form1_FormClosed(sender As System.Object, e As System.Windows _
        .Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        If OLApp IsNot Nothing Then
            System.Runtime.InteropServices.Marshal.ReleaseComObject(OLApp)
        End If
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) _
        Handles Button1.Click
        Dim OlNavigationFolder As Outlook.NavigationFolder

        If OlNavigationGroup IsNot Nothing Then
            OlNavigationFolder = OlNavigationGroup _
                .NavigationFolders(ComboBox1.SelectedIndex + 1)
            If OlNavigationFolder IsNot Nothing Then
                OlNavigationPan.CurrentModule = CalendarModule
                OlNavigationFolder.IsSelected = True
            End If
        Else
            MsgBox("OlNavigationGroup is nothing")
        End If
    End Sub
End Class

Shared Calendar 的 MAPIFolder是没有办法获得的。我们只能获得NavigationFolder。

相关资源:http://download.csdn.net/detail/tx_officedev/4086064

posted @ 2012-02-24 09:32  许阳 无锡  阅读(201)  评论(0编辑  收藏  举报