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

見通しが既に開かれている場合、それは終了して閉じられます。これが私の問題です。見通しを閉じずに、作成されたすべてのオブジェクトと余分なプロセスを削除して解放する必要があります

4

2 に答える 2

0

次のコード行を削除するだけです。

Call objOLApp.Quit()

設定します=Nothingが、アプリを終了しないでください... 開いたままです。プログラムで接続されていないだけです。

于 2013-04-02T13:04:09.537 に答える
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 に答える