Close a specific instance of Excel (undesired) with VBA

Giuseppe

New Member
Joined
Feb 5, 2014
Messages
2
Hi all,</SPAN>
It has been two full days that I’m trying to solve this issue, but no lack so far. My knowledge in programming with VBA are limited, so I hope you know how to solve this.</SPAN>

Basically, I open a program as an object with VBA and I pass to this object some date. The program, after make some calculation and obtain the results, it will place them in the same file from when the module contains its call is. This procedure is done several times, and should in theory terminate only when all the data set have been process.</SPAN>

The problem is that after 27 cycles, for an unknown reason (this mean that I do not know if is excel causing it or the program I call as an object), a second excel instance is open in which the same workbook that I’m actually working on try to be open. This file is exactly the same expect for the path. The path of this new file, which is the exact copy of the file I’m working with, is always the same and it really look like the original file has been copy and paste in that location.</SPAN>

Now, I will love to understand why this is happening, but since I have no control of the program code that I call as an object, I would just like to be able to catch the moment that a second instance of Excel is being open, and be able to close it automatically with VBA.</SPAN>

Based on some other post present in this community, to detect how many instance are open I can place the following code (suggested from Tom Urtis and slightly modified):</SPAN>

Sub InstanceCount()</SPAN>
Dim objList As Object, objType As Object, strObj$</SPAN>
strObj = "Excel.exe"</SPAN>
Set objType = GetObject("winmgmts:").ExecQuery("select * from win32_process where name='" & strObj & "'")</SPAN>
If objType.Count > 1 Then ‘ Do something</SPAN>
End Sub</SPAN>


After some code has been done and know when the problem is occurring. But how do I close the instance and delete that file from the undesired location?</SPAN>

Any help is appreciate</SPAN>

Giuseppe</SPAN></SPAN>
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi,
Actually I'm very disperate about this. If you have an other solution I'll like to try.
For example, there is a way to stop anyone or every program to not create an other excel instance.

Again, any help will be appraciate
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top