如何判断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
本文提供了几种实用的方法来检查Excel是否正在运行,并给出了具体的VBA代码示例来关闭已打开的Excel进程。一种方法是使用VBA代码通过查找并终止进程的方式实现;另一种方法则是直接创建一个对象并调用其Quit方法。
1135

被折叠的 条评论
为什么被折叠?



