Microsoft Excel
--
Questions
--
Followers
Top Experts
The case is this:
I ofte find that Excel leaves running, seemingly empty processes running in the background after I close an Excel workbook. I have a RPA-software (UFT) that uses VBScript and Excel to do its work, so I typically open up an Excel workbook and have the script getting its input data from there. My problem is that when VBS shall access the Excel workbook it typically picks one of the empty background processes, and not the workbook I opened.
I have tried everything I can think of to go throug the processes on the pc and kill the Excel processes, but to no avail. I can find them, no problem, but I cannot seem to be able to kill them off without manually open the Task manager and close them there, one by one until only the correct process, the one listed under Apps and not under Background processes is the only one left.
Can anyone please help me with this?
Thank you very much!
All the best from Iver in Oslo, Norway
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Dim oShell : Set oShell = CreateObject("WScript.Shell")
oShell.Run "taskkill /im EXCEL.EXE", , True
Try that.And this is so no cmd window shows.
Dim oShell : Set oShell = CreateObject("WScript.Shell")
oShell.Run "cmd /c taskkill /im EXCEL.EXE", 0, True
Dim oShell
Set oShell = CreateObject("Shell.Application")
oShell.Run "taskkill /im EXCEL.exe", ,True
This triggers the following error:The object does not support the specified property or method.
What am I doing wrong?
Brgds
IVer
Dim oShell : Set oShell = CreateObject("WScript.Shell")
oShell.Run "cmd /c taskkill /im EXCEL.EXE", 0, True






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
IVer
The only difference is that the shadow processes are in the background, not visible on the taskbar and listed under background processes, and the one I want to keep is a regular opened workbook listed under apps in the task manager.
If I loop through workbooks using GetObject("Excel.Applicati
Do
found = false
Set excel_Gen = eval("GetObject(,"&CHR(34)&"Excel.Application"&CHR(34)&")")
sts = Err.Number
If TypeName(excel_Gen) = "Empty" Then
msgbox "UFT cannot find Excel. Must abort."
exittest 'Special UFT command
End If
found = true
cntWb = 0
Set excel_Sheet = nothing 'Necessary to avoid error message when checking on it later
If sts = 0 Then
'Loop through workbooks to try and find the correct worksheet
For each wb in excel_Gen.workbooks
cntWb = cntWb + 1
wb.activate
For i = 1 to wb.Worksheets.Count
Set ws = wb.Worksheets(i)
'The correct sheet should have the following contents in E1 or D1 - Not 100% proof, but close enough
'See if I have found the rigth sheet
If ws.cells(1,5).value = "FORSIKRING" or ws.cells(1,4).value = "FORSIKRING" Then
Set excel_Sheet = ws
Exit For
End If
Next
If not (excel_sheet is nothing) Then
Exit Do 'found the right one. No further search necessary
End If
Next
'Close empty instance and search for next
excel_Gen.Quit
Set excel_Gen = Nothing
count = count + 1
ElseIf sts <> 429 Then
Msgbox Err.Number & ": " & Err.description
End If
If count > 10 Then
Msgbox "Cannot stop Excel processes. Must be done manually before I can continnue."
count = 5
End If
Loop While found = true
This is able to find the correct Excel Sheet to use, but not able to kill off the other processes. And since it cannot kill them off it keeps on finding the same process over and over.Sorry for the somewhat messy code which has become this way after a lot of trying and failing.

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
EXCEL.EXE PID 7908 Running User:IVE
EXCEL.EXE PID 22808 Running User:IVE
EXCEL.EXE PID 17264 Running User:IVE
and I cannot see anything there that make it possible to pick which one is the foreground process and which ones are the ones to kill.
IVer






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
If I only had a way to connect the found PID with the process found with GetObject("Excel.Applicati
IVer
So the VBscript opens the Excel, and thereby always tracking the correct Excel window, instead of having Excel already open and trying afterwards to get VBscript to get the correct one.

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-powershell-1.0/ff730962(v=technet.10)
IVer






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Would be nice to solve the original problem though, since I am using Excel a lot, both with UFT, PL/SQL and on its own. And it is leaving this background processes running all the time, also when only using Excel itself. And in that particular case I would consider it to be a bug.
Come to think of it, I could perhaps make a small .exe with VB.Net and just call it from VBScript. THat would be a possibility of course.
Thanks!
IVer
https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-powershell-1.0/ff730962(v=technet.10)

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Solution 2: Make a small .exe with VB.Net and just call it from VBScript.
Brgds
IVer in Oslo
Brgds
IVer in Oslo






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Microsoft Excel
--
Questions
--
Followers
Top Experts
Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.