0
次のコードは、タスクマネージャで2つのEXCEL.EXEを開きます。タスクマネージャから2番目のEXCEL.EXEを終了するためにグローバル変数を宣言する方法
Form1が終了しているときにタスクマネージャから2番目のEXCEL.EXEを強制終了します。
Imports Microsoft.Office.Interop
Public Class Form1
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
'Kill all EXCEL.EXE process from Task Manager
For Each prog As Process In Process.GetProcessesByName("EXCEL")
prog.Kill()
Next
Dim FirstxlApp As New Excel.Application 'Open first EXCEL.EXE in the Task Manager
Dim datestart As Date = Date.Now
Dim SecondxlApp As New Excel.Application 'Open second EXCEL.EXE in the Task Manager
Dim dateEnd As Date = Date.Now
SecondxlApp.Visible = True
Dim wb1 As Excel.Workbook
wb1 = SecondxlApp.Workbooks.Open("C:\Book1.xlsx")
End Sub
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim xlp() As Process = Process.GetProcessesByName("EXCEL")
For Each Process As Process In xlp
If Process.StartTime >= datestart And Process.StartTime <= dateEnd Then
Process.Kill()
Exit For
End If
Next
End Sub
End Class
以下のエラーを解決するにはグローバル変数を宣言するにはどうすればよいですか?彼らは唯一のメソッド内で宣言されているよう