473,851 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1857
Have you tried to create a SINGLE Word object, and use
ObjWordApp.Docu ments.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=Crea teObject("Word. Application)

For Each docFileName In DocFileNameList

'Open each document, one at a time
objDoc=objWordA pp.Documents.Op en(docFileName)

'Do your printing/processing with the Document object

objDoc.Close(Fa lse)

Next

objWordApp.Quit
"Derek Hart" <de********@yah oo.comwrote in message
news:%2******** **********@TK2M SFTNGP02.phx.gb l...
>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
approximatel y 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
12092
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 "word automation". I have foud a lot of exemple to use it but I need your precious help to
12
5543
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 and office XP components installed. ie I have word/access/excel 2k/xp/2003 installed. I tried to do a usual access 2k to word 2k automation yet I get the error "Automation Error" "ClassFactory cannot supply requested class" when on late binding try...
6
3970
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 open all four PPT files at once, and would loop through queriers for ever client and create custom presentations. Now there are 8 files, nearly 500 slides and the computer is bogging down with trying to open them all at once. I know that Access...
2
2618
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 don't know why it crash some time.
4
7691
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 handle the automation. So, i'm using the following code to create a new word document: ---Code---
0
6309
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 reformating, after the merge. This is a full description of my needs. I have a C# class library that creates two Crystal Reports, and then exports them to the harddrive as Word documents. One's orientation is landscape, the other is portrait. I then...
2
2627
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 course) which will merge the contents of files which I will point ie. 1.doc and 2.doc into one file: "12.doc" I've just tried to find smth in MSDN help, and in google archive of programing groups but still I don't know how to do it:(
4
11138
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 done this? Does it seem possible? I followed the instructions from a sample on the Microsoft knowledge base but it only seems to work when creating a VB.NET Windows .EXE, not an VB.NET ASP app.
5
2529
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 to have a word template on the server which is populated in the asp.net application and then streamed out to the user. Also acceptable would be to open a template on the client's computer using automation and fill this file (if this is possible)....
10
3305
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 document in pdf and that is all I want done with it. How can I tell it to close the file without prompting me for anything? For Each row As DataRow In myDt.Rows Dim objWord As Application Dim objDoc As Document objWord =...
0
9744
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11011
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10725
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10352
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9503
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7072
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4142
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3178
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.