Solved

Handling multiple instances of Word with multiple documents when Automating Word

Posted on 2007-03-26
7
265 Views
Last Modified: 2013-11-07
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
0
Comment
Question by:PantoffelSlippers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 

Author Comment

by:PantoffelSlippers
ID: 18897398
Doubled the points!

Any suggestions?

Thanks
0
 
LVL 6

Expert Comment

by:nirojexpert
ID: 18930545
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.
0
 
LVL 6

Expert Comment

by:nirojexpert
ID: 18930547
you should also close the objects after creating it


set wordApp = nothing
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:PantoffelSlippers
ID: 18931840
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?
0
 
LVL 6

Accepted Solution

by:
nirojexpert earned 500 total points
ID: 18936726
try getObject first, if it generates error at runtime, then use the createObject
on error goto err_getObj

set s = getObject("...")
goto withOBJ
err_getObj:
on error resume 0 'cancel on error
'we will have to create it
set s = createObject("....")

withObj:


about olb for .net, i think the same.
0
 

Author Comment

by:PantoffelSlippers
ID: 18975293
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
0
 
LVL 6

Expert Comment

by:nirojexpert
ID: 18977593
the object name is independent of the class name. so do not worry about it.
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question