Link to home
Start Free TrialLog in
Avatar of PantoffelSlippers
PantoffelSlippersFlag for South Africa

asked on

Handling multiple instances of Word with multiple documents when Automating Word

Experts,

I need to generate a word document with data stored in SQL Server 2005 using VB.Net.  

I use to do this sort of thing a lot in VB6 and I'm new to .Net.  I remeber that having different instances of Word open and multiple documents per Word instance always was a n problem until I found some VB6 code to take care of it. Never really understood the code though ....

My question is:  what is the correct way handling this problem in .Net?

Thanks
Avatar of PantoffelSlippers
PantoffelSlippers
Flag of South Africa image

ASKER

Doubled the points!

Any suggestions?

Thanks
there are two methods createObject and getObject
use the getObject to get a previous instance of the application.

or create a word application at global level

open each doument using the same word application object.
you should also close the objects after creating it


set wordApp = nothing
OK but how do I know if an existing instance of Word is already running?  If Word is already open I would not like to open another instance.  

Also, in VB6 I would add a reference to the Word OLB file; is there a replacement in .Net for this or do I still add a COM object / OLB file?
ASKER CERTIFIED SOLUTION
Avatar of nirojexpert
nirojexpert
Flag of Nepal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Any idea what goes inside the brackets?

set s = CreateObject("xxx")  :  what should xxx be?  Would the value of xxx change depending on the version of Word installed?  (2000, 2002, 2003, 2007).

Also, if I'm correct, you are using VB6 syntax above- will it be the same for .Net?

Thanks
the object name is independent of the class name. so do not worry about it.