Opening word document

J

John

Hi

I am using the code given at the end to open a word document from within
vb.net. It works fine the first time but the second time I get the error;

Unhandled Exception: System.Runtime.InteropServices.COMException
(0x800706BA): The RPC server is unavailable.
at Word.ApplicationClass.get_Documents()

The error occurs on the line WordDoc = WordApp.Documents.Add(<Template
name>)

Any idea what I am doing wrong? Surprisingly, if I open a backup copy of the
project (with the same code as far as I can see), it works! Does this mean
something has gone corrupt?

Thanks

Regards



= Code Follows ==================

Public Class clsOfficeWrapper

Private WithEvents WordApp As Word.Application
Private WithEvents WordDoc As Word.Document

Public Sub NewFax(ByVal Temp As String)

If WordApp Is Nothing Then
WordApp = New Word.Application
WordApp.Options.ShowControlCharacters = False
End If

WordDoc = WordApp.Documents.Add(Temp) '<== This lines gives error, the
second time round
With WordDoc
.ActiveWindow.Visible = True
End With

WordApp.Activate()
WordDoc = Nothing ' Kill the refernce only - not the document itself
End Sub

....

End Class
 
H

Herfried K. Wagner [MVP]

* "John said:
The following article seems to suggest that I need to use wrdApp.Visible =
True immediately after creating word object. Anyone lese had this
problem?>

Does the article solve your problem?
 
J

John

I think it has. I am still testing it though and I am using word 2000 not
word 97 which the article refers to.

Pretty weird, it worked all along and as the delivery date approaches it
starts to go all haywire.

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top