我正在使用 Outlook 2010 和 Visual Studio 2010
我试过这段代码,它工作正常:
Dim objOLApp As Outlook.Application
Dim objFolder As Outlook.MAPIFolder
Dim objExplorer As Outlook.Explorer
Dim objSubFolder As Outlook.MAPIFolder
Dim objCalenderItem As Outlook.AppointmentItem
Dim objOutlookFolders As Outlook.Folders
Dim intFolderCtr As Integer
Dim intSubFolderCtr As Integer
Dim intAppointmentCtr As Integer
' >> Initialize The Base Objects
objOLApp = New Outlook.Application
objOutlookFolders = objOLApp.Session.Folders
' >> Loop Through The PST Files Added n Outlook
For intFolderCtr = 1 To objOutlookFolders.Count
objFolder = objOutlookFolders.Item(intFolderCtr)
objExplorer = objFolder.GetExplorer()
' >> Loop Through The Folders In The PST File
For intSubFolderCtr = 1 To objExplorer.CurrentFolder.Folders.Count
objSubFolder = objExplorer.CurrentFolder.Folders.Item(intSubFolderCtr)
' >> Check if Folder Contains Appointment Items
If objSubFolder.DefaultItemType = Outlook.OlItemType.olAppointmentItem Then
' >> Loop Through Appointment Items
For intAppointmentCtr = 1 To objSubFolder.Items.Count
' >> Get Teh Calender Item From The Calender Folder
objCalenderItem = objSubFolder.Items.Item(intAppointmentCtr)
' >> Process Appointment Item Accordingly
If objCalenderItem.Start.ToShortDateString = Today.Date.ToShortDateString Then
DataGridView1.Rows.Add(1)
DataGridView1.Rows(DataGridView1.Rows.Count - 1).Cells("col_seq").Value = DataGridView1.Rows.Count
DataGridView1.Rows(DataGridView1.Rows.Count - 1).Cells("col_subject").Value = objCalenderItem.Subject
DataGridView1.Rows(DataGridView1.Rows.Count - 1).Cells("col_date").Value = objCalenderItem.Start.ToShortDateString
DataGridView1.Rows(DataGridView1.Rows.Count - 1).Cells("col_time").Value = objCalenderItem.Start.ToShortTimeString
End If
Next
End If
Next
Next
' >> Close Application
Call objOLApp.Quit()
' >> Release COM Object
Call System.Runtime.InteropServices.Marshal.ReleaseComObject(objOLApp)
objOLApp = Nothing
如果 Outlook 已经打开,它将被终止并关闭,这是我的问题,我需要在不关闭 Outlook 的情况下删除并释放所有创建的对象和额外进程