Word object error

D

Dan

My VB program interfaces with the Word application and document objects to read Word documents. On my system the program works as expected. When I install the program on another system (using the Package and Deployment Wizard), I get the following error message and the program aborts when I execute the program and try to create the Word application object:

Automation error. Object is not connected to server.

What does this mean? How do I fix it?

Sincerely,
Dan
 
J

Jezebel

In this context, 'server' refers to the Word application. (Word is the
'server', your VB app is the 'client'). The message usually means that Word
is failing to 'serve' the requests from your app. At the simplest, this
sequence will cause the error:

1. In your VB app, create a reference to Word: Set MyWord =
CreateObject("Word.Application")

2. Make the word instance visible: MyWord.Visible = TRUE

3. Manually switch to Word and close it.

4. Back in your app, try to use your MyWord object. At this point VB has a
valid object (ie MyWord is not nothing); but there is no Word instance to
support the object.


This on its own doesn't explain why your app works on one machine but not
another. There are other things that might happen at step 3 to cause the
problem -- such as other add-ins or automacros. You can also get this error
if the target machine is using a different version of Word.




Dan said:
My VB program interfaces with the Word application and document objects to
read Word documents. On my system the program works as expected. When I
install the program on another system (using the Package and Deployment
Wizard), I get the following error message and the program aborts when I
execute the program and try to create the Word application object:
 
D

Dan

Thank you for your helpful explanation. As far as I know, there was nothing else going on when my program was running, and I know we didn't switch to Word manually and close it.

Your comment about different versions of Word is a definite possibility. How can I make my code work with any recent version of Word? Does the object library for Word on the system where I do my development limit me to working only with that version of Word on every other system?

Sincerely,
Dan
 
J

Jezebel

The trick is to use late binding. Instead of adding a project reference to
the Word library and using 'Dim WordApp as Word.Application', omit the
library reference and use:

Dim WordApp as object
Set WordApp = CreateObject("Word.Application")

That returns a reference to whatever version of Word the user has on their
system. It makes programming a little harder because you don't get the
intellisense assistance -- I use the library method for development, then
change to CreateObject for final testing and compilation.

You might also need to check the version number and work differently or
abort if the version of Word is too old ...

If WordApp.Version = 8 then
... [code for Word 97]
elseif WordApp.Version > 8 then
... [code for Word 2000 or later]
end if

-- or --

If WordApp.Version < 9 then
Err.Raise Number:=errBadVersion, Description:= "This application
requires Word 2000 or later"
end if


Dan said:
Thank you for your helpful explanation. As far as I know, there was
nothing else going on when my program was running, and I know we didn't
switch to Word manually and close it.
Your comment about different versions of Word is a definite possibility.
How can I make my code work with any recent version of Word? Does the object
library for Word on the system where I do my development limit me to working
only with that version of Word on every other system?
 

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