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>
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>