|
分類:[VB.NET/VB2005 以降]
お世話になります。
以下12行目のコメントを外すと(シート追加)エクセルのプロセスが閉じなくなります。
解決方法をご教授頂けると助かります。
-------------------
Imports Microsoft.Office.Interop
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim xlApplication As New Excel.Application
Dim xlbooks As Excel.Workbooks = xlApplication.Workbooks
Dim xlBook As Excel.Workbook = xlbooks.Open("c:\test.xlsx")
Dim xlSheets As Excel.Sheets = xlBook.Worksheets
Dim xlSheet As Excel.Worksheet = xlSheets(1)
Dim xlCells As Excel.Range = xlSheet.Cells
'xlSheet = xlSheets.Add()
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlCells)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets)
xlBook.Close(SaveChanges:=False)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlbooks)
xlApplication.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApplication)
End Sub
End Class
|