QTP中如何判断Excel进程是否存在?
发布日期:2022-02-07 00:54:32 浏览次数:279 分类:技术文章

本文共 733 字,大约阅读时间需要 2 分钟。

如何判断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博客,转载请标明出处:

转载地址:https://blog.csdn.net/jims55555/article/details/5840291 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:如何让你的QTP脚本执行效率更高?
下一篇:自动化框架的一些构思

发表评论

最新留言

不错!
[***.144.177.141]2024年04月10日 03时12分15秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章