タイトル : Excelが正常終了出来ません 投稿日 : 2005/03/30(Wed) 22:07 投稿者 : 匿名希望
いつも参考にさせて頂いてます。 OSはXPと、2000で開発しています。 下記プログラムは、XPのマシンでは正常に終了しますが、 2000ですと、メモリが"read"になることは出来ませんでした。と メッセージが出てしまいます。 行のコピーをコメントにすると、エラーは出ません。 エクセルは、Visible = True のままで、閉じずにユーザーが 印刷設定などをして、終了してもらいます。 どなたか、教えていただけませんでしょうか? 宜しくお願い致します。 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim xlApp As Excel.Application Dim xlsSheet As Excel.Worksheet Dim xlsBooks As Excel.Workbooks Dim xlsBook As Excel.Workbook Dim xlsSheets As Excel.Sheets Dim objCells As Excel.Range Dim objRows As Excel.Range Dim R1 As Excel.Range Dim RCopy As Excel.Range Dim RPaste As Excel.Range xlApp = New Excel.Application xlsBooks = xlApp.Workbooks xlsBook = xlsBooks.Open("c:\Test.xls") xlsSheets = xlsBook.Worksheets xlsSheet = xlsSheets.Item(1) objCells = xlsSheet.Cells objRows = xlsSheet.Rows R1 = DirectCast(objCells._Default(1, 1), Excel.Range) R1.Value = "" R1.Value = Format(Today, "yyyy/MM/dd") System.Runtime.InteropServices.Marshal.ReleaseComObject(R1) RCopy = DirectCast(objRows.Rows("1:5"), Excel.Range) RCopy.Copy() RPaste = DirectCast(objRows.Rows("6:6"), Excel.Range) RPaste.Insert() System.Runtime.InteropServices.Marshal.ReleaseComObject(RCopy) System.Runtime.InteropServices.Marshal.ReleaseComObject(RPaste) R1 = DirectCast(objCells._Default(6, 1), Excel.Range) R1.Value = "" R1.Value = Format(Today, "yyyy/MM/dd") System.Runtime.InteropServices.Marshal.ReleaseComObject(R1) System.Runtime.InteropServices.Marshal.ReleaseComObject (objCells) 'Cells の開放 System.Runtime.InteropServices.Marshal.ReleaseComObject (objRows) 'Rows の開放 xlApp.Visible = True System.Runtime.InteropServices.Marshal.ReleaseComObject (xlsSheet) 'xlSheet の開放 System.Runtime.InteropServices.Marshal.ReleaseComObject (xlsSheets) 'xlSheets の開放 System.Runtime.InteropServices.Marshal.ReleaseComObject (xlsBook) 'xlBook の開放 System.Runtime.InteropServices.Marshal.ReleaseComObject (xlsBooks) 'xlBooks の開放 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) 'xlApp を開放 End Sub |