Exception when closing Word document

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
 
S

Stephany Young

Clearly, the Close method required 3 arguments and you have only supplied
one.
 
C

Chris Mahoney

That worked, and I've possibly found a bug in VB - the tooltip lists
all three arguments as optional.
 

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