タイトル : Excelタスクの消えるタイミング 投稿日 : 2009/07/01(Wed) 09:03 投稿者 : ケイ
いつも拝見し勉強させていただいております。 今回、ちょっと気になったのでご質問させていただきます。 下の様なプログラムで、Set xlApp = Nothingを処理した時点では まだタスクマネージャのプロセスにはExcel表示が残っていて、 Form_Load(End Sub)を抜けるとプロセスのExcel表示消えるのは 正解なのでしょうか? ちなみに「For Each ObjSht In xlBook.Worksheets」の手前に Set xlSheet = Nothing xlBook.Close Set xlBook = Nothing xlApp.Quit Set xlApp = Nothing と記述して、「開いてすぐ閉じる」様な記述にしてみれば、 Set xlApp = Nothingを処理した時点でプロセスのExcel表示消えます。 何か「For Each ObjSht In xlBook.Worksheets」〜「Set xlSheet = Nothing」間の 記述で省略形など不適切な部分があるのでしょうか? ご教示宜しくお願い致します。 Option Explicit Private TgtShtName As String Private RetShtName As String ----------------------------- Private Sub Form_Load() '参照設定:Microsoft Excel 11.0 Object Library Dim xlApp As Excel.Application Dim xlBook As Excel.Workbook Dim xlSheet As Excel.Worksheet Dim ObjSht As Excel.Worksheet '目的のシート名格納 TgtShtName = "7月度" Set xlApp = CreateObject("Excel.Application") Set xlBook = xlApp.Workbooks.Open("C:\ExcelTextControl.xls") Set xlSheet = xlBook.Worksheets(1) xlApp.Visible = True For Each ObjSht In xlBook.Worksheets If ObjSht.Name = TgtShtName Then RetShtName = ObjSht.Name Exit For End If Next Set xlSheet = Nothing xlBook.Close Set xlBook = Nothing xlApp.Quit Set xlApp = Nothing End Sub |