Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim xlApp As Object = CreateObject("Excel.Application") Dim xlBooks As Object = xlApp.Workbooks Dim xlBook As Object = xlBooks.Add() Try xlApp.Visible = True Finally MRComObject(xlBook) MRComObject(xlBooks) MRComObject(xlApp) End Try End Sub 'https://hanatyan.sakura.ne.jp/dotnet/index.html 'VB2005/VB2008/VB2010 用 ''' <summary> ''' COMオブジェクトの参照カウントをデクリメントします。 ''' </summary> ''' <typeparam name="T">(省略可能)</typeparam> ''' <param name="objCom"> ''' COM オブジェクト持った変数を指定します。 ''' このメソッドの呼出し後、この引数の内容は Nothing となります。 ''' </param> ''' <param name="force"> ''' すべての参照を強制解放する場合はTrue、現在の参照のみを減ずる場合はFalse。 ''' </param> Public Shared Sub MRComObject(Of T As Class)(ByRef objCom As T, Optional ByVal force As Boolean = False) If objCom Is Nothing Then Return End If Try If System.Runtime.InteropServices.Marshal.IsComObject(objCom) Then If force Then System.Runtime.InteropServices.Marshal.FinalReleaseComObject(objCom) Else System.Runtime.InteropServices.Marshal.ReleaseComObject(objCom) End If End If Finally objCom = Nothing End Try End Sub