如何在一个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.youkuaiyun.com/detail/tx_officedev/4086064

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值