Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Office interop printing problem

Office interop printing problem

Scheduled Pinned Locked Moved Visual Basic
helpcsharpcomsysadmin
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mSh1985
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups