QA@IT
«質問へ戻る

追記

2
本文
 ご回答の程、よろしくお願い致します。
 
 
+
+追記いたします。
+xlRange~の2行に加え、xlStartCell = DirectCast(xlWorkSheet.Cells(1, 18), MyExcel.Range)の「(1,18)」、xlEndCell = DirectCast(xlWorkSheet.Cells(nRow, 18 + nColumn), MyExcel.Range)
+の「(nRow, 18 + nColumn)」をコメントアウトすると、プロセスが解放されました。
+セルの範囲指定をすることが何かまずいのでしょうか?

COMオブジェクトの解放について

いつもお世話になっております。
散々既出の内容で申し訳ないのですが、下記のコードを実行すると、
どうしてもエクセルのプロセスが残ってしまいます。
下記の書き方では不十分なのでしょうか?
'''

    '=======================================================
   ' 宣言部
    '=======================================================
    Dim xlAplication As New MyExcel.Application
    Dim xlWorkbooks As MyExcel.Workbooks
    Dim xlWorkbook As MyExcel.Workbook
    Dim xlSheets As MyExcel.Sheets
    Dim xlWorkSheet As MyExcel.Worksheet
    Dim xlRange As MyExcel.Range
    Dim xlStartCell As MyExcel.Range
    Dim xlEndCell As MyExcel.Range

    Dim sTemplatePath As String = ""
    Dim i As Long = 0

    Dim nColumn As Long = 0
    Dim nRow As Long = 0

    Dim nRtn As Integer

    MakeExcelFile = 0

    Try
        '-------------------------------------------------------
        ' テンプレートパスの設定
        '-------------------------------------------------------
        sTemplatePath = <<省略>>         

        '-------------------------------------------------------
        ' Excelを開いてオブジェクトを設定
        '-------------------------------------------------------
        'xlAplication = New MyExcel.Application
        xlWorkbooks = xlAplication.Workbooks

        Try
            ' テンプレート(WorkBook)を開く
            xlWorkbook = xlWorkbooks.Open(sTemplatePath)
            Try
                ' シートの設定
                xlSheets = xlAplication.Worksheets
                Try
                    ' シートを開く
                    xlWorkSheet = xlSheets(1)
                    Try
                        ' 開始セルを設定
                        xlStartCell = DirectCast(xlWorkSheet.Cells(1, 18), MyExcel.Range)
                        Try
                            ' 終了セルを設定
                            nColumn = objModels.GetLength(0)
                            nRow = objModels.GetLength(1)
                            xlEndCell = DirectCast(xlWorkSheet.Cells(nRow, 18 + nColumn), MyExcel.Range)
                            Try
                                '=======================================================
                                ' ここから値の出力処理
                                '=======================================================
                                '-------------------------------------------------------
                                ' 出力 (ここが問題となっている箇所です)
                                '-------------------------------------------------------
                                xlRange = xlWorkSheet.Range(xlStartCell, xlEndCell)
                                xlRange.Value = objModels
                                Try
                                    '-------------------------------------------------------
                                    ' エクセル保存
                                    '-------------------------------------------------------
                                    xlAplication.DisplayAlerts = False
                                    xlWorkbook.SaveAs(<<省略>>)
                                    xlAplication.DisplayAlerts = True
                                Finally
                                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlRange)
                                End Try
                            Finally
                                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlEndCell)
                            End Try
                        Finally
                            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlStartCell)
                        End Try

                    Finally
                        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkSheet)
                    End Try
                Finally
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlSheets)
                End Try
            Finally
                '-------------------------------------------------------
                ' ワークブックを閉じる
                '-------------------------------------------------------
                xlAplication.DisplayAlerts = False
                xlWorkbook.Close()
                xlAplication.DisplayAlerts = True
                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkbook)
            End Try
        Finally
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkbooks)
        End Try

    Catch ex As Exception

        MakeExcelFile = -1
        Throw ex

    Finally
        '-------------------------------------------------------
        ' Excelを閉じる
        '-------------------------------------------------------
        xlAplication.DisplayAlerts = False
        xlAplication.Quit()
        xlAplication.DisplayAlerts = True
        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlAplication)

    End Try

'''

ご回答の程、よろしくお願い致します。

追記いたします。
xlRange~の2行に加え、xlStartCell = DirectCast(xlWorkSheet.Cells(1, 18), MyExcel.Range)の「(1,18)」、xlEndCell = DirectCast(xlWorkSheet.Cells(nRow, 18 + nColumn), MyExcel.Range)
の「(nRow, 18 + nColumn)」をコメントアウトすると、プロセスが解放されました。
セルの範囲指定をすることが何かまずいのでしょうか?

いつもお世話になっております。
散々既出の内容で申し訳ないのですが、下記のコードを実行すると、
どうしてもエクセルのプロセスが残ってしまいます。
下記の書き方では不十分なのでしょうか?
'''

        '=======================================================
       ' 宣言部
        '=======================================================
        Dim xlAplication As New MyExcel.Application
        Dim xlWorkbooks As MyExcel.Workbooks
        Dim xlWorkbook As MyExcel.Workbook
        Dim xlSheets As MyExcel.Sheets
        Dim xlWorkSheet As MyExcel.Worksheet
        Dim xlRange As MyExcel.Range
        Dim xlStartCell As MyExcel.Range
        Dim xlEndCell As MyExcel.Range

        Dim sTemplatePath As String = ""
        Dim i As Long = 0

        Dim nColumn As Long = 0
        Dim nRow As Long = 0

        Dim nRtn As Integer

        MakeExcelFile = 0

        Try
            '-------------------------------------------------------
            ' テンプレートパスの設定
            '-------------------------------------------------------
            sTemplatePath = <<省略>>         

            '-------------------------------------------------------
            ' Excelを開いてオブジェクトを設定
            '-------------------------------------------------------
            'xlAplication = New MyExcel.Application
            xlWorkbooks = xlAplication.Workbooks

            Try
                ' テンプレート(WorkBook)を開く
                xlWorkbook = xlWorkbooks.Open(sTemplatePath)
                Try
                    ' シートの設定
                    xlSheets = xlAplication.Worksheets
                    Try
                        ' シートを開く
                        xlWorkSheet = xlSheets(1)
                        Try
                            ' 開始セルを設定
                            xlStartCell = DirectCast(xlWorkSheet.Cells(1, 18), MyExcel.Range)
                            Try
                                ' 終了セルを設定
                                nColumn = objModels.GetLength(0)
                                nRow = objModels.GetLength(1)
                                xlEndCell = DirectCast(xlWorkSheet.Cells(nRow, 18 + nColumn), MyExcel.Range)
                                Try
                                    '=======================================================
                                    ' ここから値の出力処理
                                    '=======================================================
                                    '-------------------------------------------------------
                                    ' 出力 (ここが問題となっている箇所です)
                                    '-------------------------------------------------------
                                    xlRange = xlWorkSheet.Range(xlStartCell, xlEndCell)
                                    xlRange.Value = objModels
                                    Try
                                        '-------------------------------------------------------
                                        ' エクセル保存
                                        '-------------------------------------------------------
                                        xlAplication.DisplayAlerts = False
                                        xlWorkbook.SaveAs(<<省略>>)
                                        xlAplication.DisplayAlerts = True
                                    Finally
                                        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlRange)
                                    End Try
                                Finally
                                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlEndCell)
                                End Try
                            Finally
                                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlStartCell)
                            End Try

                        Finally
                            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkSheet)
                        End Try
                    Finally
                        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlSheets)
                    End Try
                Finally
                    '-------------------------------------------------------
                    ' ワークブックを閉じる
                    '-------------------------------------------------------
                    xlAplication.DisplayAlerts = False
                    xlWorkbook.Close()
                    xlAplication.DisplayAlerts = True
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkbook)
                End Try
            Finally
                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkbooks)
            End Try

        Catch ex As Exception

            MakeExcelFile = -1
            Throw ex

        Finally
            '-------------------------------------------------------
            ' Excelを閉じる
            '-------------------------------------------------------
            xlAplication.DisplayAlerts = False
            xlAplication.Quit()
            xlAplication.DisplayAlerts = True
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlAplication)

        End Try


'''

ご回答の程、よろしくお願い致します。



追記いたします。
xlRange~の2行に加え、xlStartCell = DirectCast(xlWorkSheet.Cells(1, 18), MyExcel.Range)の「(1,18)」、xlEndCell = DirectCast(xlWorkSheet.Cells(nRow, 18 + nColumn), MyExcel.Range)
の「(nRow, 18 + nColumn)」をコメントアウトすると、プロセスが解放されました。
セルの範囲指定をすることが何かまずいのでしょうか?

edit

2
本文
 いつもお世話になっております。
 散々既出の内容で申し訳ないのですが、下記のコードを実行すると、
 どうしてもエクセルのプロセスが残ってしまいます。
-xlRange = xlWorkSheet.Range(xlStartCell, xlEndCell)
-↑この記述を消すと、正常にプロセスが消えることから、
-Rangeオブジェクトの解放がうまくいってないのだとは思うのですが、
 下記の書き方では不十分なのでしょうか?
 '''
 

COMオブジェクトの解放について

いつもお世話になっております。
散々既出の内容で申し訳ないのですが、下記のコードを実行すると、
どうしてもエクセルのプロセスが残ってしまいます。
下記の書き方では不十分なのでしょうか?
'''

    '=======================================================
   ' 宣言部
    '=======================================================
    Dim xlAplication As New MyExcel.Application
    Dim xlWorkbooks As MyExcel.Workbooks
    Dim xlWorkbook As MyExcel.Workbook
    Dim xlSheets As MyExcel.Sheets
    Dim xlWorkSheet As MyExcel.Worksheet
    Dim xlRange As MyExcel.Range
    Dim xlStartCell As MyExcel.Range
    Dim xlEndCell As MyExcel.Range

    Dim sTemplatePath As String = ""
    Dim i As Long = 0

    Dim nColumn As Long = 0
    Dim nRow As Long = 0

    Dim nRtn As Integer

    MakeExcelFile = 0

    Try
        '-------------------------------------------------------
        ' テンプレートパスの設定
        '-------------------------------------------------------
        sTemplatePath = <<省略>>         

        '-------------------------------------------------------
        ' Excelを開いてオブジェクトを設定
        '-------------------------------------------------------
        'xlAplication = New MyExcel.Application
        xlWorkbooks = xlAplication.Workbooks

        Try
            ' テンプレート(WorkBook)を開く
            xlWorkbook = xlWorkbooks.Open(sTemplatePath)
            Try
                ' シートの設定
                xlSheets = xlAplication.Worksheets
                Try
                    ' シートを開く
                    xlWorkSheet = xlSheets(1)
                    Try
                        ' 開始セルを設定
                        xlStartCell = DirectCast(xlWorkSheet.Cells(1, 18), MyExcel.Range)
                        Try
                            ' 終了セルを設定
                            nColumn = objModels.GetLength(0)
                            nRow = objModels.GetLength(1)
                            xlEndCell = DirectCast(xlWorkSheet.Cells(nRow, 18 + nColumn), MyExcel.Range)
                            Try
                                '=======================================================
                                ' ここから値の出力処理
                                '=======================================================
                                '-------------------------------------------------------
                                ' 出力 (ここが問題となっている箇所です)
                                '-------------------------------------------------------
                                xlRange = xlWorkSheet.Range(xlStartCell, xlEndCell)
                                xlRange.Value = objModels
                                Try
                                    '-------------------------------------------------------
                                    ' エクセル保存
                                    '-------------------------------------------------------
                                    xlAplication.DisplayAlerts = False
                                    xlWorkbook.SaveAs(<<省略>>)
                                    xlAplication.DisplayAlerts = True
                                Finally
                                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlRange)
                                End Try
                            Finally
                                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlEndCell)
                            End Try
                        Finally
                            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlStartCell)
                        End Try

                    Finally
                        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkSheet)
                    End Try
                Finally
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlSheets)
                End Try
            Finally
                '-------------------------------------------------------
                ' ワークブックを閉じる
                '-------------------------------------------------------
                xlAplication.DisplayAlerts = False
                xlWorkbook.Close()
                xlAplication.DisplayAlerts = True
                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkbook)
            End Try
        Finally
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkbooks)
        End Try

    Catch ex As Exception

        MakeExcelFile = -1
        Throw ex

    Finally
        '-------------------------------------------------------
        ' Excelを閉じる
        '-------------------------------------------------------
        xlAplication.DisplayAlerts = False
        xlAplication.Quit()
        xlAplication.DisplayAlerts = True
        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlAplication)

    End Try

'''

ご回答の程、よろしくお願い致します。

いつもお世話になっております。
散々既出の内容で申し訳ないのですが、下記のコードを実行すると、
どうしてもエクセルのプロセスが残ってしまいます。
下記の書き方では不十分なのでしょうか?
'''

        '=======================================================
       ' 宣言部
        '=======================================================
        Dim xlAplication As New MyExcel.Application
        Dim xlWorkbooks As MyExcel.Workbooks
        Dim xlWorkbook As MyExcel.Workbook
        Dim xlSheets As MyExcel.Sheets
        Dim xlWorkSheet As MyExcel.Worksheet
        Dim xlRange As MyExcel.Range
        Dim xlStartCell As MyExcel.Range
        Dim xlEndCell As MyExcel.Range

        Dim sTemplatePath As String = ""
        Dim i As Long = 0

        Dim nColumn As Long = 0
        Dim nRow As Long = 0

        Dim nRtn As Integer

        MakeExcelFile = 0

        Try
            '-------------------------------------------------------
            ' テンプレートパスの設定
            '-------------------------------------------------------
            sTemplatePath = <<省略>>         

            '-------------------------------------------------------
            ' Excelを開いてオブジェクトを設定
            '-------------------------------------------------------
            'xlAplication = New MyExcel.Application
            xlWorkbooks = xlAplication.Workbooks

            Try
                ' テンプレート(WorkBook)を開く
                xlWorkbook = xlWorkbooks.Open(sTemplatePath)
                Try
                    ' シートの設定
                    xlSheets = xlAplication.Worksheets
                    Try
                        ' シートを開く
                        xlWorkSheet = xlSheets(1)
                        Try
                            ' 開始セルを設定
                            xlStartCell = DirectCast(xlWorkSheet.Cells(1, 18), MyExcel.Range)
                            Try
                                ' 終了セルを設定
                                nColumn = objModels.GetLength(0)
                                nRow = objModels.GetLength(1)
                                xlEndCell = DirectCast(xlWorkSheet.Cells(nRow, 18 + nColumn), MyExcel.Range)
                                Try
                                    '=======================================================
                                    ' ここから値の出力処理
                                    '=======================================================
                                    '-------------------------------------------------------
                                    ' 出力 (ここが問題となっている箇所です)
                                    '-------------------------------------------------------
                                    xlRange = xlWorkSheet.Range(xlStartCell, xlEndCell)
                                    xlRange.Value = objModels
                                    Try
                                        '-------------------------------------------------------
                                        ' エクセル保存
                                        '-------------------------------------------------------
                                        xlAplication.DisplayAlerts = False
                                        xlWorkbook.SaveAs(<<省略>>)
                                        xlAplication.DisplayAlerts = True
                                    Finally
                                        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlRange)
                                    End Try
                                Finally
                                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlEndCell)
                                End Try
                            Finally
                                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlStartCell)
                            End Try

                        Finally
                            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkSheet)
                        End Try
                    Finally
                        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlSheets)
                    End Try
                Finally
                    '-------------------------------------------------------
                    ' ワークブックを閉じる
                    '-------------------------------------------------------
                    xlAplication.DisplayAlerts = False
                    xlWorkbook.Close()
                    xlAplication.DisplayAlerts = True
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkbook)
                End Try
            Finally
                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkbooks)
            End Try

        Catch ex As Exception

            MakeExcelFile = -1
            Throw ex

        Finally
            '-------------------------------------------------------
            ' Excelを閉じる
            '-------------------------------------------------------
            xlAplication.DisplayAlerts = False
            xlAplication.Quit()
            xlAplication.DisplayAlerts = True
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlAplication)

        End Try


'''

ご回答の程、よろしくお願い致します。

質問を投稿

COMオブジェクトの解放について

いつもお世話になっております。
散々既出の内容で申し訳ないのですが、下記のコードを実行すると、
どうしてもエクセルのプロセスが残ってしまいます。
xlRange = xlWorkSheet.Range(xlStartCell, xlEndCell)
↑この記述を消すと、正常にプロセスが消えることから、
Rangeオブジェクトの解放がうまくいってないのだとは思うのですが、
下記の書き方では不十分なのでしょうか?
'''

    '=======================================================
   ' 宣言部
    '=======================================================
    Dim xlAplication As New MyExcel.Application
    Dim xlWorkbooks As MyExcel.Workbooks
    Dim xlWorkbook As MyExcel.Workbook
    Dim xlSheets As MyExcel.Sheets
    Dim xlWorkSheet As MyExcel.Worksheet
    Dim xlRange As MyExcel.Range
    Dim xlStartCell As MyExcel.Range
    Dim xlEndCell As MyExcel.Range

    Dim sTemplatePath As String = ""
    Dim i As Long = 0

    Dim nColumn As Long = 0
    Dim nRow As Long = 0

    Dim nRtn As Integer

    MakeExcelFile = 0

    Try
        '-------------------------------------------------------
        ' テンプレートパスの設定
        '-------------------------------------------------------
        sTemplatePath = <<省略>>         

        '-------------------------------------------------------
        ' Excelを開いてオブジェクトを設定
        '-------------------------------------------------------
        'xlAplication = New MyExcel.Application
        xlWorkbooks = xlAplication.Workbooks

        Try
            ' テンプレート(WorkBook)を開く
            xlWorkbook = xlWorkbooks.Open(sTemplatePath)
            Try
                ' シートの設定
                xlSheets = xlAplication.Worksheets
                Try
                    ' シートを開く
                    xlWorkSheet = xlSheets(1)
                    Try
                        ' 開始セルを設定
                        xlStartCell = DirectCast(xlWorkSheet.Cells(1, 18), MyExcel.Range)
                        Try
                            ' 終了セルを設定
                            nColumn = objModels.GetLength(0)
                            nRow = objModels.GetLength(1)
                            xlEndCell = DirectCast(xlWorkSheet.Cells(nRow, 18 + nColumn), MyExcel.Range)
                            Try
                                '=======================================================
                                ' ここから値の出力処理
                                '=======================================================
                                '-------------------------------------------------------
                                ' 出力 (ここが問題となっている箇所です)
                                '-------------------------------------------------------
                                xlRange = xlWorkSheet.Range(xlStartCell, xlEndCell)
                                xlRange.Value = objModels
                                Try
                                    '-------------------------------------------------------
                                    ' エクセル保存
                                    '-------------------------------------------------------
                                    xlAplication.DisplayAlerts = False
                                    xlWorkbook.SaveAs(<<省略>>)
                                    xlAplication.DisplayAlerts = True
                                Finally
                                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlRange)
                                End Try
                            Finally
                                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlEndCell)
                            End Try
                        Finally
                            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlStartCell)
                        End Try

                    Finally
                        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkSheet)
                    End Try
                Finally
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlSheets)
                End Try
            Finally
                '-------------------------------------------------------
                ' ワークブックを閉じる
                '-------------------------------------------------------
                xlAplication.DisplayAlerts = False
                xlWorkbook.Close()
                xlAplication.DisplayAlerts = True
                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkbook)
            End Try
        Finally
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkbooks)
        End Try

    Catch ex As Exception

        MakeExcelFile = -1
        Throw ex

    Finally
        '-------------------------------------------------------
        ' Excelを閉じる
        '-------------------------------------------------------
        xlAplication.DisplayAlerts = False
        xlAplication.Quit()
        xlAplication.DisplayAlerts = True
        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlAplication)

    End Try

'''

ご回答の程、よろしくお願い致します。

いつもお世話になっております。
散々既出の内容で申し訳ないのですが、下記のコードを実行すると、
どうしてもエクセルのプロセスが残ってしまいます。
xlRange = xlWorkSheet.Range(xlStartCell, xlEndCell)
↑この記述を消すと、正常にプロセスが消えることから、
Rangeオブジェクトの解放がうまくいってないのだとは思うのですが、
下記の書き方では不十分なのでしょうか?
'''

        '=======================================================
       ' 宣言部
        '=======================================================
        Dim xlAplication As New MyExcel.Application
        Dim xlWorkbooks As MyExcel.Workbooks
        Dim xlWorkbook As MyExcel.Workbook
        Dim xlSheets As MyExcel.Sheets
        Dim xlWorkSheet As MyExcel.Worksheet
        Dim xlRange As MyExcel.Range
        Dim xlStartCell As MyExcel.Range
        Dim xlEndCell As MyExcel.Range

        Dim sTemplatePath As String = ""
        Dim i As Long = 0

        Dim nColumn As Long = 0
        Dim nRow As Long = 0

        Dim nRtn As Integer

        MakeExcelFile = 0

        Try
            '-------------------------------------------------------
            ' テンプレートパスの設定
            '-------------------------------------------------------
            sTemplatePath = <<省略>>         

            '-------------------------------------------------------
            ' Excelを開いてオブジェクトを設定
            '-------------------------------------------------------
            'xlAplication = New MyExcel.Application
            xlWorkbooks = xlAplication.Workbooks

            Try
                ' テンプレート(WorkBook)を開く
                xlWorkbook = xlWorkbooks.Open(sTemplatePath)
                Try
                    ' シートの設定
                    xlSheets = xlAplication.Worksheets
                    Try
                        ' シートを開く
                        xlWorkSheet = xlSheets(1)
                        Try
                            ' 開始セルを設定
                            xlStartCell = DirectCast(xlWorkSheet.Cells(1, 18), MyExcel.Range)
                            Try
                                ' 終了セルを設定
                                nColumn = objModels.GetLength(0)
                                nRow = objModels.GetLength(1)
                                xlEndCell = DirectCast(xlWorkSheet.Cells(nRow, 18 + nColumn), MyExcel.Range)
                                Try
                                    '=======================================================
                                    ' ここから値の出力処理
                                    '=======================================================
                                    '-------------------------------------------------------
                                    ' 出力 (ここが問題となっている箇所です)
                                    '-------------------------------------------------------
                                    xlRange = xlWorkSheet.Range(xlStartCell, xlEndCell)
                                    xlRange.Value = objModels
                                    Try
                                        '-------------------------------------------------------
                                        ' エクセル保存
                                        '-------------------------------------------------------
                                        xlAplication.DisplayAlerts = False
                                        xlWorkbook.SaveAs(<<省略>>)
                                        xlAplication.DisplayAlerts = True
                                    Finally
                                        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlRange)
                                    End Try
                                Finally
                                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlEndCell)
                                End Try
                            Finally
                                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlStartCell)
                            End Try

                        Finally
                            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkSheet)
                        End Try
                    Finally
                        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlSheets)
                    End Try
                Finally
                    '-------------------------------------------------------
                    ' ワークブックを閉じる
                    '-------------------------------------------------------
                    xlAplication.DisplayAlerts = False
                    xlWorkbook.Close()
                    xlAplication.DisplayAlerts = True
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkbook)
                End Try
            Finally
                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkbooks)
            End Try

        Catch ex As Exception

            MakeExcelFile = -1
            Throw ex

        Finally
            '-------------------------------------------------------
            ' Excelを閉じる
            '-------------------------------------------------------
            xlAplication.DisplayAlerts = False
            xlAplication.Quit()
            xlAplication.DisplayAlerts = True
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlAplication)

        End Try


'''

ご回答の程、よろしくお願い致します。