- - PR -
【VB.NET】エクセルのアプリケーションエラーについて
1
投稿者 | 投稿内容 |
---|---|
|
投稿日時: 2004-02-18 15:28
VB.NETで参照元エクセルをコピーして編集を行い
エクセルを出力するプログラムを作成しています。 その出力したエクセルを保存または、保存せずに終了すると エクセルのアプリケーションエラーになってしまいます。 但し、エクセルを終了する前に、VB.NETを終了した場合は エクセルのアプリケーションエラーは出ません。 宜しくお願いします。 プログラムは以下の通りです。 Dim xlApp As Excel.Application = Nothing Dim xlBook1 As Excel.Workbook = Nothing Dim xlBook2 As Excel.Workbook = Nothing xlApp = CType(CreateObject("Excel.Application"), Excel.Application) xlBook1 = xlApp.Workbooks.Open(filename) xlBook2 = xlApp.Workbooks.Add xlBook1.Sheets.Item("原紙").Copy(after:=xlBook2.Sheets.Item(xlApp.SheetsInNewWorkbook)) xlBook1.Close(False, , ) xlApp.DisplayAlerts = False For intCnt = 1 To 3 xlBook2.Sheets("Sheet" & CStr(intCnt)).Delete() Next xlApp.DisplayAlerts = True xlBook2.Sheets.Item("原紙").Range("A1").Value = "aa" xlBook2.Sheets.Item("原紙").Range("A2").Value = "bb" xlBook2.Sheets.Item("原紙").Range("A3").Value = "cc" xlBook2.Sheets.Item("原紙").Range("A4").Value = "dd" xlBook2.Sheets.Item("原紙").Range("A5").Value = "ee" xlBook2.Sheets.Item("原紙").Range("B1").Value = "ff" xlBook2.Sheets.Item("原紙").Range("B2").Value = "gg" xlBook2.Sheets.Item("原紙").Range("B3").Value = "hh" xlBook2.Sheets.Item("原紙").Range("B4").Value = "ii" xlBook2.Sheets.Item("原紙").Range("B5").Value = "jj" xlBook2.Sheets.Item("原紙").Range("C1").Value = "kk" xlBook2.Sheets.Item("原紙").Range("C2").Value = "ll" xlBook2.Sheets.Item("原紙").Range("C3").Value = "mm" xlBook2.Sheets.Item("原紙").Range("C4").Value = "nn" xlBook2.Sheets.Item("原紙").Range("C5").Value = "oo" xlApp.Visible = True If Not xlBook1 Is Nothing Then System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook1) xlBook1 = Nothing End If If Not xlBook2 Is Nothing Then System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook2) xlBook2 = Nothing End If If Not xlApp Is Nothing Then System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) xlApp = Nothing End If GC.Collect() |
1