0

我正在使用 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 的情况下删除并释放所有创建的对象和额外进程

4

2 回答 2

0
    objDoc.Close()
    objDoc.Application.Quit()
    objDoc.Application.DDETerminateAll()
    GC.Collect()
    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(objDoc)<-- interop only


   try these something should work i have a similar problem  and good luck
于 2014-01-30T08:07:10.467 回答
0

只需删除这行代码:

Call objOLApp.Quit()

设置它=Nothing但不要退出应用程序......它保持打开状态,你只是没有在程序中附加到它。

于 2013-04-02T13:04:09.537 回答