Interop Word & VB problem

S

Steve

I'm using Visual Studio .NET (not 2003), and am
developing a class that works with Word theough the
Office PIAs (Interop). I can open word and do things
with it programatically, but I can't close it.
Specifically, when I try to call the Quit() method on the
application object, VB gives me the following error:

'Quit' is ambiguous across the inherited
interfaces 'Microsoft.Office.Interop.Word._Application'
and 'Microsoft.Office.Interop.Word.ApplicationEvents3_Even
t'


Huh? Seems odd to me... All I'm doing is performing an
XSLTransform on some XML data, which changes it to HTML,
then opening the HTML in Word and saving it as a .doc
or .rtf file. It all works, including the file save, but
I can't call Quit() without getting the above error.
That leaves Word running in memory... Which is a very bad
thing.

I've included the source for the entire class for
reference. Help!

- Steve

------------ Begin Class code ---------------------
Imports System.IO
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Interop
Imports System.Xml
Imports System.Xml.Xsl

Public Class clsWordGen

#Region " Globals "
Public sTempDir As String = "c:\temp\"
Public gTempFile As Guid
Public sFullTempPath As String
#End Region


Public Sub CreateWordDoc(ByVal sXMLFilePath As
String, ByVal sXSLFilePath As String, ByVal sOutFilePath
As String)
Dim myXslTransform As New XslTransform()
Try
myXslTransform.Load(sXSLFilePath)
gTempFile.NewGuid()
sFullTempPath = sTempDir & gTempFile.ToString
& ".html"
myXslTransform.Transform(sXMLFilePath,
sFullTempPath)

Dim WordApp As New Word.Application()
Dim objDoc As New Word.Document()

objDoc = WordApp.Documents.Open(sFullTempPath)
objDoc.SaveAs(sOutFilePath)

WordApp.Quit()

WordApp = Nothing

Marshal.ReleaseComObject(WordApp)
GC.Collect()
GC.WaitForPendingFinalizers()
Catch e As Exception
' pass exception up to caller
Throw e
End Try
End Sub

End Class
 
H

Herfried K. Wagner [MVP]

Hello,

Steve said:
I'm using Visual Studio .NET (not 2003), and am
developing a class that works with Word theough the
Office PIAs (Interop). I can open word and do things
with it programatically, but I can't close it.
Specifically, when I try to call the Quit() method on the
application object, VB gives me the following error:

'Quit' is ambiguous across the inherited
interfaces 'Microsoft.Office.Interop.Word._Application'
and 'Microsoft.Office.Interop.Word.ApplicationEvents3_Even

BUG: Visual Basic .NET "'[Method]' is ambiguous across the inherited
interfaces" Error Message When Using Office Automation
http://support.microsoft.com/?kbid=315981
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top