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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System.Runtime.InteropServices.Marshal.GetActiveObject

Status
Not open for further replies.

sheila11

Programmer
Joined
Dec 27, 2000
Messages
251
Location
US
Hi all,

Will this line return to me reference to running Word app. even if that app. is not created by the current thread?

myWordObj = System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application")

TIA,
Sheila
 
After testing your code....it appears that it will interact with an Office document not created by your application.

If multiple instances of word is open and myWordObj.Quit(false) is called....all of the instances are closed.

Also it seems that the instance that has or had focus last will receive the commands. i.e. Insert Text,etc

Scott
Programmer Analyst
<{{><
 
Thanks, Scott.

Is there any way to know if an existing Word process belongs to "this" thread ?

Actually I am running word automation on server using multiple threads. (Each thread is working on an instance of Word.) And I notice that word doesn't always close down when I call Quit and set the reference to Nothing. So I was trying to see if I could kill it.... without harming the other instances...!

Any thoughts, suggestions, ... ?
TIA,
Sheila
 
Yes, JohnYingling.

I tried:
myWordObj.Quit(false)
and also:
myWordObj.Quit(Word.WdSaveOptions.wdDoNotSaveChanges)

..with:
System.Runtime.InteropServices.Marshal.ReleaseComObject(myWordObj)
myWordObj = Nothing
GC.Collect()

and also:
GC.WaitForPendingFinalizers()

Also, reinstalled Word on the machine.. with the required patches... !

Some of the Word instances disappear on Quit. Some stay on .. from 1 or 2 to several minutes... 10 - 15 or more!
 
OK. I believe that the Release is needed, but I do not "know" that, except that with the Interops I have generated for COM Dlls we must use to communicate with an Application Service Provider. Without "release", strange things happen.

Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top