Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

One process, many Instances. How to identify them

Status
Not open for further replies.

Jukko69

Technical User
May 4, 2005
4
IT
Hi, I am trying to solve an issue but I do not know how. Sorry for my english.
On a computer, Excel is automatically launched by some script and this can happen more than one time.
So I can have two o three files opened by excel in the same moment.
I have to quit only one determinated instance of excel and not all of the open ones.
I know how to quit excel but this closes all the instances and all the files.
In the process list I see always only one excel instance and I do not know how to identify better than I do.
Thank you in advance for you help
Luca
 
Hi,

What you appear to have is ONE instance of the Excel Application Object within which is contained multiple instances of Excel Workbook Objects.

So what you need to do is to Close the Workbooks you do not want.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
 
Hi, yes I have to close only one between the workbooks, but how with vbscript?
Thank you
 
Please post the code you are currently using for this process.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
 
This is the code I actually use.


Function fctExcelKiller()
sQuery = "SELECT * FROM Win32_Process WHERE Name LIKE '%Excel.exe%'"
Set objItems = objWMIService.ExecQuery(sQuery)
For Each objItem In objItems
objItem.Terminate
Next
End Function
 
Code:
'
   Function fctExcelKiller()
   sQuery = "SELECT * FROM Win32_Process WHERE Name LIKE '%Excel.exe%'"
   Set objItems = objWMIService.ExecQuery(sQuery)

   [b]With objItem In objItems
       For i = 2 To .Count
           .Workbooks(i).Close
       Next
   End With[/b]
End Function

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
 
Erm ... I'd be s teeny bit surprised if WMI was returning a Excel COM object here ...
 
Put a BREAK [highlight #FCE94F]here[/highlight]
Code:
Function fctExcelKiller()
sQuery = "SELECT * FROM Win32_Process WHERE Name LIKE '%Excel.exe%'"
Set [b]objItems[/b] = objWMIService.ExecQuery(sQuery)
[highlight #FCE94F]For Each objItem In objItems[/highlight]
objItem.Terminate
Next
End Function
Run your code to the BREAK, then Select objItems and open a Watch Window to inspect this object. Please report back your observations

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
 
Thank you so much for your answers. I'm sorry SkipVought, I don't know what you mean when you say Watch Window, I am italian and the italian software names and their menu functions are a little bit different. I went in the internet looking for softwares with Watch Window, Maybe I could find it in Microsoft Script Debugger or anything else?
Meanwhile I am trying with the workbooks names to choose between the open excel sheets. I will go on tomorrow with some other test to understand if it could be enough. Thank you again. Luca
 
Oops[blush]

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top