16,552
社区成员
发帖
与我相关
我的任务
分享
'
' Verify the Excel file to populate exists.
'
Dim strExcelFile As String = "C:\Application_Directory\MyExcel.xls"
If Not IO.File.Exists(strExcelFile) Then Return
'
' Start Microsoft Excel and set it visible.
'
myExcel = New Excel.Application
If myExcel Is Nothing Then
Throw (New Exception("Failed to Start Microsoft Excel."))
Else
myExcel.Visible = True
myExcel.WindowState = Excel.XlWindowState.xlMaximized
'
' Get the process ID of the Excel instance. This is used
' in the Closing Event to prevent orphaned Excel processes.
'
Dim aProcesses() As Process = Process.GetProcesses
Dim i As Integer
For i = 0 To aProcesses.GetUpperBound(0)
If aProcesses(i).MainWindowHandle.ToString = myExcel.Hwnd.ToString Then
myExcelPID = aProcesses(i).Id
Exit For
End If
Next
End If