Office interop printing problem
-
Not really a visual basic problem, but i didnt know what forum to use, but my code is in vb.net :) I have a program which has to print a bunch of documents, after printing a random number of documents this error is thrown: "Runtime.InteropServices.COMException (0x80010105): The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT)) " I have written this testprogram which throws the same error
Imports wrd = Microsoft.Office.interop
...
Private Shared moapp As wrd.Word.Application
Private Shared odoc As wrd.Word.Document
...Private Sub test()
moapp = New wrd.Word.ApplicationClass().Application
For i As Integer = 0 To 100
odoc = moapp.Documents.Add("\\bur-131.cmc.Be\Tools\INFORMATICA\ZZorg\bevestziek.doc")
moapp.Selection.GoTo(What:=wrd.Word.WdGoToItem.wdGoToBookmark, Name:="bwNaam")
With moapp.ActiveDocument.Bookmarks
.DefaultSorting = wrd.Word.WdBookmarkSortBy.wdSortByName
.ShowHidden = False
End With
moapp.Selection.TypeText(Text:="whoopie" & i.ToString())sOriginalPrinter = moapp.ActivePrinter moapp.ActivePrinter = "\\\\S31W40F\\PRINT075" With moapp.ActiveDocument.PageSetup .FirstPageTray = 261 '257 .OtherPagesTray = 261 '257 End With
moapp.Application.PrintOut(FileName:="", Range:=wrd.Word.WdPrintOutRange.wdPrintAllDocument, Item:= _
wrd.Word.WdPrintOutItem.wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wrd.Word.WdPrintOutPages.wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0)While moapp.BackgroundPrintingStatus = 0 End While moapp.ActivePrinter = sOriginalPrinter odoc.SaveAs("C:\\somelocation\\temp.doc") odoc.Close() Next System.Runtime.InteropServices.Marshal.ReleaseComObject(odoc) odoc = Nothing moapp.Quit() System.Runtime.InteropServices.Marshal.ReleaseComObject(moapp) moapp = Nothing GC.Collect() GC.WaitForPendingFinalizers()
End Sub
Sometimes it throws the error when opening the document, the other time when printing the document.. The problem occurs on a Vista Enterprise SP1, Office 2003 and only on a HP Laserjet 2430dtn printer. On another type of printer the cod