Click to See Complete Forum and Search --> : Office XP Interop


WillemM
December 3rd, 2002, 02:34 AM
I am working on a piece of code that prints out a Word document from my VB.NET program on a predefined time. It does print, but not shutdown the Word application....

I have this code now, but it won't compile since VS.NET complains about ambigious names when I put in wrdApp.Quit() function.... :(


If m_type = enumType.Word Then
Dim wrdApp As New Microsoft.Office.Interop.Word.Application()
Dim wrdDoc As New Microsoft.Office.Interop.Word.Document()

wrdDoc = wrdApp.Documents.Open(m_command)

wrdDoc.PrintOut()

wrdApp.Application.Quit()
End If


Anyone can solve this ?

Athley
December 3rd, 2002, 04:25 AM
This is a bug.... workarounds in the following article.....

Bug (http://support.microsoft.com/default.aspx?scid=kb;en-us;315981)

/Leyan

WillemM
December 3rd, 2002, 12:53 PM
Thanks :)

Dozo_1st
July 15th, 2003, 09:02 AM
try adding this code:

oDocument.Close(SaveChanges:=False)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oDocument)
oDocument = Nothing
oWord.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord)
oWord = Nothing

suc6

D. :rolleyes:

WillemM
July 15th, 2003, 10:48 AM
Ok, but I already had the solution... :)

Dozo_1st
July 15th, 2003, 07:14 PM
Just using Quit will give u problems when calling the Word instance again. Quit does not destroy the instance. You have to create a new instance of the Word object. And then you would have 2 Word instances running during your App.
Just using code:
oWord = CreateObject(,"WordApplication")
will fill up your memory, hence slowing down the machine and eventually crash Word (if not the machine).