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!

GetObject with multiple processes

Status
Not open for further replies.

ag

Programmer
Nov 5, 1998
31
GB
Can anyone assist me with the GetObject call please.<br><br>Scenario: MS Word97 instantiated via VB application using CreateObject or GetObject. <br><br>MS Word may open many times on the client machine. These sessions may be user created, MAPI sessions (Outlook etc) or VB created.<br><br>The application closes references to the MS Word object and hooks back into it later to preserve resources and as part of a necessary app design.<br><br><br>Question: Given that there may be multiple instances of Word running, how can I ensure that I get hold of the correct instance using GetObject? I need to do this to close down any instances of MS Word opened by my app.<br><br>TIA<br><br>Andrew<br><br><br><br><br>
 
Andrew,<br><br>Could you use FindWindow to pick up instances if Word?<br><br>Mike<br><br>Public Declare Function FindWindow Lib &quot;user32&quot; Alias &quot;FindWindowA&quot; (ByVal lpClassName As String, ByVal lpWindowName As String) As Long<br><br>Public Declare Function SetForegroundWindow Lib &quot;user32&quot; Alias &quot;SetForegroundWindow&quot; (ByVal hwnd As Long) As Long<br><br>Private Sub Form_Load()<br><br>Dim hdl As Long<br>Dim rc As Long<br><br>hdl = FindWindow(vbNullString, &quot;The Real Caption&quot;)<br>If hdl &gt; 0 Then<br>rc = SetForegroundWindow(hdl)<br> <p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Thanks for the reply....<br><br>I use the FindWindow function in the code to locate and position the Word app but I cannot see an obvious way to set a reference to the object.<br><br>Once I have located the correct version I need to be able use the Word object hierarchy via automation....<br><br>Andrew<br>
 
I think the problem may be that GetObject will return which ever instance of Word is handiest.&nbsp;&nbsp;I don't know of a way to have GetObject return you a specific instance.<br><br>You could try calling GetObject several times to see if it cycles through the group of running copies, and check the title property of each to see if it's the one you want.&nbsp;&nbsp;This is a long shot, however.<br><br>Chip H.<br>
 
That's right...GetObject just seems to grab what it fancies from the Task list.<br><br>It's that 'For each Task in Tasklist' construct I just can't seem to find in the help file anywhere :)<br><br>Andrew<br><br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top