View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.vb.winapi,microsoft.public.win32.programmer.kernel
William DePalo [MVP VC++] William DePalo [MVP VC++] is offline
external usenet poster
 
Posts: 1
Default Visible Instances of an Application

"TCook" wrote in message
...
I am building something that needs to grab a certain instance of MS Excel.
Unfortunately, "GetObject" randomly chooses an instance and, therefore, is
not appropriate / robust enough by itself. In pseudo code, what I need is
below:

For each pProcess in Processes
If instr(pProcess.Name, "Excel") 0 And pProcess.Visible = True
Then
Set MyAppInstance = pProcess.Instance

Exit For
End If
Next pProcess


This isn't really a kernel issue but as you posted here, and as you seem to
be after a process list, CreateToolhelp32Snapshot(), Process32First(), and
Process32Next() will get that for you. You can check the docs for the
ProcessEntry32 structure to see if it contains the data that you need.

Just by the way, the main window for the version of Excel I have installed
here has a window class name of "XLMAIN". If the class name is constant
across versions you could use EnumWindows() to list the windows and
GetClassName() to filter out Excel's.

Regards,
Will