RPC Error?

S

scorpion53061

Hi big problem here. I am automating MS Word. I created a global instance at
program startup to avoid having the end user have to wait a extremely long
time to get thier report.

The first time a report is generated everyting runs fine.

The second time an attempt is made to write a report I get a RPC Server is
unavailable error. How can I avoid this?

Private Word As New Word.ApplicationClass

'code starts the instance
Public Function getInstance1() As Word.ApplicationClass
Dim regVersion As RegistryKey
Dim keyValue As String
Dim versionnumber As Integer = 9
Do
keyValue = "Software\\Microsoft\\Office\\" & versionnumber &
".0\\Word"
regVersion = Registry.LocalMachine.OpenSubKey(keyValue, False)
If regVersion Is Nothing Then
versionnumber = versionnumber + 1
If versionnumber = 14 Then
WordInstalled = False
Exit Do
End If
Else
WordInstalled = True
regVersion.Close()
Exit Do
End If
Loop
'to avoid exception if users do not have Word 2000 or above
If WordInstalled = True Then
Return Word
Else
Exit Function
End If
End Function

'code to start talking to this instance in another form

Dim oDoc As New Word.Document
oDoc = getInstance1.Documents.Add(Template:="Normal",
NewTemplate:=False, DocumentType:=0)
'writing our document here

'code to end

oDoc.Saved = True
oDoc.Content.Application.ActiveWindow.Close()
 

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