Hello, I made an export to excel which works fine. Now there is still one problem. If Excel gets an error caused by different reasons there is still a process in my task manager EXCEL.EXE which must be closed manually before i can export a new excel file. Now, what i want to do is write some code to clear this exel.exe process. Till now i haven’t find a solution to do this. Has somebody got a solution ? Thx in advance
Scripting is always a good idea. One can kick a process out with a VB script. By using WMI one can achieve great results on this.
Sub KillExe(strExePath) Dim wbemServices, wbemObject, wbemObjectSet,intProcessId, intStatus Dim strMessage Set wbemServices = GetObject("winmgmts:\\" & strComputer) Set wbemObjectSet = wbemServices.InstancesOf("Win32_Process") For Each wbemObject In wbemObjectSet If LCase(wbemObject.Name) = strExePath Then intStatus = wbemObject.Terminate(0) If intStatus = 0 Then strMessage = "Process "& strExePath & " " & intProcessId & " has been killed." Else strMessage = "Failed to kill process "& strExePath & " " & intProcessId & "." End If objLogFile.WriteLine(strMessage) End If Next Set wbemServices = Nothing Set wbemObjectSet = Nothing End Sub
Try this code… SHELL(‘taskkill /F /IM excel.exe’); Cheers…