tagCANDY CGI VBレスキュー(花ちゃん) の Visual Basic 2010 用 掲示板(VB.NET 掲示板)
VBレスキュー(花ちゃん) の Visual Basic 2010 用 掲示板(VB.NET 掲示板)
[ツリー表示へ]  [ワード検索]  [Home]

タイトル Re: Excelのプロセスが残る問題
投稿日: 2005/03/18(Fri) 13:16
投稿者魔界の仮面弁士
> objRange = stWork.Range(objCells._Default(1, 1), objCells._Default(1, 3))
> で範囲指定すると ReleaseComObjectを行ってもプロセスが残ってしまいます。

えーと。それはそうでしょうね。

『objCells._Default(1, 1)』や『objCells._Default(1, 3)』が返す
Rangeオブジェクトを、どうやって ReleaseComObject しているのでしょうか? (^^;


修正したサンプルを投稿しておきますね。(あえて、Imports宣言無しで記述しています)

なお、当方では Excel 2003 の PIA(プライマリ相互運用機能アセンブリ)を使っているので、
名前空間は Excel ではなく、Microsoft.Office.Interop.Excel となります。
(Excel 2002 の場合は、KB 328912 から PIA を入手してください)

'------------
Dim Ex2003 As Microsoft.Office.Interop.Excel.Application
Dim Books As Microsoft.Office.Interop.Excel.Workbooks
Dim Book As Microsoft.Office.Interop.Excel.Workbook
Dim Sheets As Microsoft.Office.Interop.Excel.Sheets
Dim Sheet As Microsoft.Office.Interop.Excel.Worksheet
Dim R1, R2, R3, R4 As Microsoft.Office.Interop.Excel.Range

Ex2003 = New Microsoft.Office.Interop.Excel.ApplicationClass()
Ex2003.Visible = True
Books = Ex2003.Workbooks
Book = Books.Add()
Sheets = Book.Worksheets
Sheet = DirectCast(Sheets(1), Microsoft.Office.Interop.Excel.Worksheet)
R1 = Sheet.Cells

'A1 または R1C1 に相当
R2 = DirectCast(R1(1, 1), Microsoft.Office.Interop.Excel.Range)

'C1 または R1C3 に相当
R3 = DirectCast(R1(1, 3), Microsoft.Office.Interop.Excel.Range)

'A1:C1 または R1C1:R1C3 に相当
R4 = Sheet.Range(R2, R3)
R4.Merge()

R4.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter
R4.Value = "タイトル"

System.Runtime.InteropServices.Marshal.ReleaseComObject(R4)
System.Runtime.InteropServices.Marshal.ReleaseComObject(R3)
System.Runtime.InteropServices.Marshal.ReleaseComObject(R2)
System.Runtime.InteropServices.Marshal.ReleaseComObject(R1)
System.Runtime.InteropServices.Marshal.ReleaseComObject(Sheet)
System.Runtime.InteropServices.Marshal.ReleaseComObject(Sheets)

Book.SaveAs("C:\Book1.xls")
Book.Close()

System.Runtime.InteropServices.Marshal.ReleaseComObject(Book)
System.Runtime.InteropServices.Marshal.ReleaseComObject(Books)

Ex2003.Quit()

System.Runtime.InteropServices.Marshal.ReleaseComObject(Ex2003)

- 関連一覧ツリー をクリックするとツリー全体を一括表示します)

古いスレッドにレスはつけられません。