|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Exception when closing Word documentI'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. Show quoteHide quote "Chris Mahoney" <chrismaho***@gmail.com> wrote in message news:1144029893.707398.285860@z34g2000cwc.googlegroups.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 > That worked, and I've possibly found a bug in VB - the tooltip lists
all three arguments as optional.
Web browser control in VB 2003
Formula in a text box Structure vs Class Objects Q: DataGrid Sort how can I exit from a recursive subroutine? Picturebox How do I fix this code?? any ideas? Runas stored procedure in VB binding source? VS.NET Public Namespaces, classes, Function - Conceptual misunderstanding. |
|||||||||||||||||||||||