D
Derek Hart
I am using late bound Microsoft Word integration with a vb.net winforms
application. If I run code such as the following:
Dim objWord As Object
Dim objWrdDoc As Object
Dim count As Integer
Dim filename As String
filename = "c:\temp\mergedata\1.doc"
objWord = CreateObject("Word.Application")
For count = 1 To 10000
objWrdDoc = objWord.Documents.Open(filename)
objWrdDoc.PrintOut(BackGround:=False)
objWrdDoc.Close(wdDoNotSaveChanges)
Next
objWord.Quit(wdDoNotSaveChanges)
This will work with a huge loop, way more than even 10,000. Now in my actual
program I have this code, except much more logic is done to determine which
documents to print (the variable filename is constantly changing). The
objWord object is passed into another routine, and it is always passed
ByRef. All the other logic works fine, but after about 11000 documents,
Word crashes. It does not crash with a blue screen, but it just stops, and I
cannot click almost anything in Windows unless I exit my winforms
application, then I can use Windows normally. I have tried every variation
can find on how to use a late bound Word object properly, and clean it up
properly, such as statements such as these:
objWord = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
I have tried DoEvents and other things. Are there big problems running a
Word Object on the UI Thread? I understand about all the issues of not
using Word on the server that are described in the Microsoft articles, but
this application will be attended. Word simply crashes when doing this
process.
So I am looking at possibly calling Word and running VBA code in a Word
template, which I know should be pretty reliable. Or should I use VB6 to do
this? Since I can get the above code working, perhaps I should write
another .Net winforms dll that can be called to do this, but should I call
that dll late bound, and if I call it late bound, would that put it on a
separate thread?
Please help and open up a dialog on this!!!
Thank You,
Derek
application. If I run code such as the following:
Dim objWord As Object
Dim objWrdDoc As Object
Dim count As Integer
Dim filename As String
filename = "c:\temp\mergedata\1.doc"
objWord = CreateObject("Word.Application")
For count = 1 To 10000
objWrdDoc = objWord.Documents.Open(filename)
objWrdDoc.PrintOut(BackGround:=False)
objWrdDoc.Close(wdDoNotSaveChanges)
Next
objWord.Quit(wdDoNotSaveChanges)
This will work with a huge loop, way more than even 10,000. Now in my actual
program I have this code, except much more logic is done to determine which
documents to print (the variable filename is constantly changing). The
objWord object is passed into another routine, and it is always passed
ByRef. All the other logic works fine, but after about 11000 documents,
Word crashes. It does not crash with a blue screen, but it just stops, and I
cannot click almost anything in Windows unless I exit my winforms
application, then I can use Windows normally. I have tried every variation
can find on how to use a late bound Word object properly, and clean it up
properly, such as statements such as these:
objWord = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
I have tried DoEvents and other things. Are there big problems running a
Word Object on the UI Thread? I understand about all the issues of not
using Word on the server that are described in the Microsoft articles, but
this application will be attended. Word simply crashes when doing this
process.
So I am looking at possibly calling Word and running VBA code in a Word
template, which I know should be pretty reliable. Or should I use VB6 to do
this? Since I can get the above code working, perhaps I should write
another .Net winforms dll that can be called to do this, but should I call
that dll late bound, and if I call it late bound, would that put it on a
separate thread?
Please help and open up a dialog on this!!!
Thank You,
Derek