您的位置:首页 > 其它

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

2012-02-24 09:32 190 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: