掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
EXCELのプロセスに関して (ID:147412)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
返答ありがとうございます。 私の作成しているプログラムは以下のような形となっていて(ある程度加工してありますが、、、) どうしてもブレイクしたタイミングでシートを追加し、そこへ出力しようと思うとEXCELのプロセス が残ったままとなってしまいます。。。 本当に困っています。 どうか助けて下さい。 よろしくお願いします。 【プログラム内容】 '既存のEXCELファイルを開く Dim xlFilePath As String = "C:\TEST.xls" '起動時の処理 Dim xlApp As New Excel.Application Dim xlBooks As Excel.Workbooks = xlApp.Workbooks Dim xlBook As Excel.Workbook = xlBooks.Open(xlFilePath) xlApp.Visible = True ' 確認のためExcelのウィンドウを表示する Dim xlSheets As Excel.Sheets = xlBook.Worksheets Dim xlSheet As Excel.Worksheet = CType(xlSheets.Item(1), Excel.Worksheet) xlSheet = xlSheets.Item(1) 'シートの選択 xlSheet.Copy(After:=xlBook.Worksheets(1)) 'シートのコピー xlSheet = xlSheets.Item(2) '再度シートを選択 xlSheet.Name = "zz" 'シートに名前を付ける Dim x, y As Integer x = 0 y = 0 Dim fcount As Integer Dim Aコード As String Aコード = ZZZ(0).Bコード Dim strDat(20, 20) As Object For icount As Integer = 0 To count - 1 If Aコード <> ZZZ(icount).Bコード Then 'データをEXCELファイルに書き出し Dim xlRange As Excel.Range xlRange = xlSheet.Range("A1:O30") 'データの入力セル範囲 xlRange.Value = strDat 'セルへデータの入力 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange) Dim xlSheet2 As Excel.Worksheet = CType(xlSheets.Item(2), Excel.Worksheet) xlSheet2 = xlSheets.Item(2) 'シートの選択 xlSheet2.Copy(After:=xlBook.Worksheets(2)) 'シートのコピー xlSheet2 = xlSheets.Item(2) '再度シートを選択 xlSheet2.Name = "YY" 'シートに名前を付ける System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet2) Aコード = ZZZ(icount).IN_Bコード x = 0 strDat(x, 1) = ZZZ(icount).IN_XX strDat(x, 2) = ZZZ(icount).IN_YY fcount = 1 Else strDat(x, 1) = ZZZ(icount).IN_XX strDat(x, 2) = ZZZ(icount).IN_YY End If x = x + 1 Next Dim xlRange3 As Excel.Range 'データの入力セル範囲 xlRange3 = xlSheet.Range("A1:O30") 'セルへデータの入力 xlRange3.Value = strDat 'COM オブジェクトの解放 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange3) xlBooks.Close() xlApp.DisplayAlerts = False xlApp.Quit() 'COM オブジェクトの解放 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks) 'Excel のプロセス終了 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.