Exception when closing Word document

  • Thread starter Thread starter Chris Mahoney
  • Start date Start date
C

Chris Mahoney

Hi

I'm trying to print a Word document from my VB 2005 app, but I'm having
trouble.

Imports Microsoft.Office.Interop
Private oWord As Word.Application
Private WordTemplate As Object = "N:\Checklist.dot"

Public Sub PrintDocument()
Dim oDoc As Word.Document
oWord = New Word.Application
oDoc = oWord.Documents.Add(WordTemplate)
oDoc.PrintOut()
oDoc.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
oWord.Quit()
End Sub

When I run the code, the document gets printed, but then I get an error
on the .Close line:

System.Runtime.InteropServices.COMException
Exception from HRESULT: 0x800A14EC
at Microsoft.Office.Interop.Word.DocumentClass.Close(Object&
SaveChanges, Object& OriginalFormat, Object& RouteDocument)

Can anyone tell me what I am doing wrong?

Thanks
Chris
 
Clearly, the Close method required 3 arguments and you have only supplied
one.
 
That worked, and I've possibly found a bug in VB - the tooltip lists
all three arguments as optional.
 
Back
Top