如何判斷Excel進程是否存在?如果存在則關閉Excel進程。
SystemUtil.CloseProcessByName "excel.exe"
On error resume next
Dim Obj
Set Obj = GetObject(,"Excel.Application")
If Not Obj Is Nothing Then
Obj.Quit
Set Obj = Nothing
End If
或者:
' To kill excel application
CreateObject("WScript.Shell").Run "taskkill /f /im excel.exe"
'To check if excel is running use this function
msgbox "Excel is Running:" & FindProcess("EXCEL.EXE")
Function FindProcess(ByVal ProcessName)
FindProcess= False
Set Shell = CreateObject("WScript.Shell")
Set ShellResult = Shell.Exec("TaskList")
While Not ShellResult.StdOut.AtEndOfStream
If Instr(UCASE(ShellResult.StdOut.ReadLine),UCASE(ProcessName)) Then
FindProcess = True
Exit Function
End If
Wend
End Function
本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/Testing_is_believing/archive/2010/04/18/5499698.aspx