473,327 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

MS Word Automation - .Net 2.0

I have a vb.net winforms application that loops through several thousand
word documents and prints them, with the filenames being read from a SQL
database. I am using late bound code to load MS Word. I have tried loading
Word for each document, printing the doc, and exiting Word. I have also
tried loading Word for 100 documents at a time, exiting Word, and reloading
Word for the next 100 documents. I have tried many scenarios. Around
approximately 1500 documents Word seems to stop, and I will get an error
""exception has been thrown by the target of an invocation" - and Windows XP
itself is mostly frozen (cannot load any apps), until I exit my winforms
app. I am about to move to loading code inside an MS Word template directly
instead of trying to automate from dot net. I am not sure if somebody will
have direct advice on how to get this working in my winforms app, but it
would be helpful to know if it is suggested to not try to automate Word like
this from a vb.net app with such heavy printing in Word. Or should I use
VB6 to automate it. I have to use late bound because I may print in
different versions of Word. Any thoughts?

Derek Hart
May 25 '07 #1
1 1831
Have you tried to create a SINGLE Word object, and use
ObjWordApp.Documents.Open()/Close() to open/close a document in each loop.
This way, you will not create Word object 1500 time (only once), you will
not open 100 document at a time (you only open one at a time).

Something like (psedocode):

Dim objWordApp as Object
Dim objDoc As Object

objWordApp=CreateObject("Word.Application)

For Each docFileName In DocFileNameList

'Open each document, one at a time
objDoc=objWordApp.Documents.Open(docFileName)

'Do your printing/processing with the Document object

objDoc.Close(False)

Next

objWordApp.Quit
"Derek Hart" <de********@yahoo.comwrote in message
news:%2******************@TK2MSFTNGP02.phx.gbl...
>I have a vb.net winforms application that loops through several thousand
word documents and prints them, with the filenames being read from a SQL
database. I am using late bound code to load MS Word. I have tried loading
Word for each document, printing the doc, and exiting Word. I have also
tried loading Word for 100 documents at a time, exiting Word, and reloading
Word for the next 100 documents. I have tried many scenarios. Around
approximately 1500 documents Word seems to stop, and I will get an error
""exception has been thrown by the target of an invocation" - and Windows
XP itself is mostly frozen (cannot load any apps), until I exit my winforms
app. I am about to move to loading code inside an MS Word template directly
instead of trying to automate from dot net. I am not sure if somebody will
have direct advice on how to get this working in my winforms app, but it
would be helpful to know if it is suggested to not try to automate Word
like this from a vb.net app with such heavy printing in Word. Or should I
use VB6 to automate it. I have to use late bound because I may print in
different versions of Word. Any thoughts?

Derek Hart

May 25 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: mickeydisn | last post by:
Sub: C++ Word automation Extract text hello. I want extact text form a word document using a visual c++ programme. I have see a lot of documentation. and my analysis is that I must use a...
12
by: Cheval | last post by:
Has anyone had any problems with inter-office automation between MS Word and MS Access in Office 2003? I have recently installed office 2003 in a new folder and have left the older office 2000...
6
by: Colleyville Alan | last post by:
I have an application that has an Access table that stores the locations of slides in a Powerpoint file. This used to work fine when there were about 4 files and 200 slides. The database would...
2
by: kids | last post by:
Does anybody know any reason which could cause Ms. word automation to crash? I try to call word automation to open a document and use find and replace function. For some reason it works but I...
4
by: Daniel | last post by:
Hello, i have a problem with the word automation from c#. First, i want to mention, that i don't have any dependencies from word in my c#-project, i want to use the system.reflection model to...
0
by: mharris | last post by:
I need help with merging two Word documents into one through C# code. The problem isn't so much getting the documents put into one as it is maintaining the appropriate formatting, or rather...
2
by: Radek | last post by:
Hi, I have got such problem: in my directory "C:\folder" I have 3 files in MS WORD (having tables, images etc), these are: "1.doc", "2.doc", "3.doc". I want to write an application (C# of...
4
by: Yohancef Chin | last post by:
Hi, Being fairly new to .NET I am looking for a way to call MS Word from an event on a webform, and after the user is finished save that created document to an SQL Server database. Has anyone...
5
by: Daniel Walzenbach | last post by:
Hi, I need to know how I could populate a word file from within ASP.NET and stream it out to some user (I can rely on all users have at least Word XP installed). The preferable solution would be...
10
by: cj2 | last post by:
I open a word template in VB and add values to the bookmarks then save the document as as pdf. When I then go to close the document it pops up a save as dialog box. It's already saved the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.