By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,550 Members | 908 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,550 IT Pros & Developers. It's quick & easy.

Exception when closing Word document

P: n/a
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

Apr 3 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Clearly, the Close method required 3 arguments and you have only supplied
one.
"Chris Mahoney" <ch**********@gmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
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

Apr 3 '06 #2

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

Apr 4 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.