Mr Cheung,
I am aware that I did not answer your question. I felt your approach in creating multiple instances of Excel, which it is reasonable to presume leads to the problem of having several unconnected instances, was perhaps not a good approach to take. Changing the multiple instance approach to only a single instance approach would mean that instead of needing to scan all previously created and disconnected instances of Excel you'd only have one instance that would remain connected at all times.
Finding a solution to a problem, in my honest opinion, should be secondary to removing the problem all together.
To answer you question though I presume it would be possible. You will need to dip into the WinAPI as there isn't, as far as I know, an inbuilt Excel function to do it. This article here covers the API calls you'll need. Your idea to tag an instance of Excel I understand but you should do it the other way and in your application hold a reference to the process ID of the instances you create.
http://www.awprofessional.com/articles/article.asp p=366892&seqNum=3&rl=1
Again this isn't a direct answer but hopefully you can piece the code together and do what you need.
|