QTP中如何判斷Excel程式是否存在?

TIB發表於2010-04-18

如何判斷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

相關文章