Clicky

Hi,

I'm trying to open a word document from my visual basic application (I'll be using bookmarks to replace certain words in the document from vb), I figured out how to open it using a button I placed in my program. The problem I'm having is that once I close the word application and re-click the button in my visual basic program I get the following error: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
I'm assuming this error happens because VB doesn't know I closed word or something

here is my code so far :

Imports Microsoft.Office.Interop

Dim appWord As New Word.Application
Dim docWord As New Word.Document

Private Sub wordBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles wordBtn.Click

Dim appWord As New Word.Application
Dim docWord As New Word.Document

docWord = appWord.Documents.open("s:\hello.doc")
appWord.Visible = True

End Sub

I also added COM references to my project :
Microsoft Office 14.0 Object
Microsoft Word 14.0 object library

Thank you for the help!

asked 12/15/2011 12:12

FCapo's gravatar image

FCapo ♦♦


5 Answers:
You should not have a problem as it opens a new word instance every time. If you leave word open, does it work?
link

answered

CodeCruiser's gravatar image

CodeCruiser

Actually yes it does work fine if word stays open, it's just I'm pretty sure that my employees will consistently close word every time so I can't depend on it always being open, the error only occurs if word is closed and I click the button again, but I need it to open even if word was closed, is this possible?  
link

answered 2011-12-15 at 11:35:51

FCapo's gravatar image

FCapo

Remove these two lines

Dim appWord As New Word.Application
Dim docWord As New Word.Document

under import.

Have you checked the processes tab in task explorer? Is word running there in background?
link

answered 2011-12-15 at 11:46:38

CodeCruiser's gravatar image

CodeCruiser

Perfect that solved it, I actually put those two lines under the button instead of under the imports and now it opens right away, thanks for the help!
link

answered 2011-12-15 at 11:49:02

FCapo's gravatar image

FCapo

Glad to help :-)
link

answered 2011-12-15 at 11:59:57

CodeCruiser's gravatar image

CodeCruiser

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

Asked: 12/15/2011 12:12

Seen: 215 times

Last updated: 12/15/2011 04:02