The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)


  • I am using the attached code


    Private Sub StartApplicationProcess


       oWord.Visible = True

       oDoc = oWord.Documents.Open(StrStackPath)

        oWord.Visible = True

    end sub


    The variables oWord and oDoc are declared in the class as below attached


    Private WithEvents oWord As Word.Application

    Private WithEvents oDoc As Word.Document


    The sub InitialiseObject() has the below code


    Private Sub InitialiseObject()

            oWord = New Word.Application

    End Sub


    Ok, lets start! I am having a very strange issue. I am creating a word document using the documents.add method and I close word using the .Quit method, then I am calling the sub StartApplicationProcess (shown above). On the first instance everything goes well and the document is launch as per my requirements. However when I launch again the document I am having The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) in line "oDoc = oWord.Documents.Open(StrStackPath)" in sub StartApplicationProcess. I can't understand this error since I am still initialising the object oWord. Why he can't find the word to launch the document? Funnily enough, if I declare the oWord and the oDoc inside the sub StartApplicationProcess itself, I will not get the error and the document is open, but I can't afford of declaring a local variable since as shown above the variables are also being used to handle events. I also tried moving the code oWord = New Word.Application from the sub InitialiseObject to sub StartApplicationProcess but vb.net failed again. Some suggested to include the property visible = true after declaring the creation of the object. This also didn't sort out my issue.


    This is happening with office 2003.


    Your suggestion will be greatly appreciated since I really don't know how to handle this issue.



    Thursday, April 19, 2007 8:44 PM

All replies

  • Anny ideas about this issue?



    Saturday, April 21, 2007 7:15 AM
  • Further to this I've done so more troubleshooting and here are my results


    Noticed that the issue is coming from the variable oWord. As shown below the variable oWord is declared at the top level of the class as Private WithEvents oWord As Word.Application. The word docuement is opening in a normal manner. When it is closed the event is raised and therefore the document is closed. In the StartApplicationProcess the code is getting stuck in the code line oDoc = oWord.Documents.Open(StrStackPath). The rpc server is unavailable error shows that you cannot open a document if the word application is open. In my case the word application is open and visible, and if I watch the oWord variable it shows that it has been defined to open. If I change the oWord.visible = false, the word application will hide. This is another prove that oWord variable has been assigned to the word.application. If I execute the code oWord.Documents.add the error RPC server is again there


    If I don't trigger the odoc.close event the program will work normally and it will not stop if I try to open the document for x amount of times.


    Do you have any ideas what’s happening here?

    Saturday, April 21, 2007 12:14 PM