Automation error

I received the following error when trying to close a word doc from Access.  The statement I use is 'ActiveDocument.Save'.  Sometimes it works just fine.

Automation error
The RPC server is unavailable.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BUG: Starting Word Manually Uses Same Instance as Automation

The information in this article applies to:

Microsoft Visual Basic for Applications version 5.0
Microsoft Office 2000 Developer
Microsoft Word 2000
Microsoft Word 97 for Windows


You run a Visual Basic application that uses the CreateObject function to start a hidden instance of Microsoft Word. The application is idle, but it still maintains a reference to Word. Next, you manually start an instance of Word. A separate instance of Word should open, but the same instance that was created by the Visual Basic application is made active instead. If you close Word and continue to work in the Visual Basic application, the following error occurs when the application tries to use Word objects because Word is no longer running:

Run-time error '-2147023174 (800706ba)':
Automation error
This automation error translates to "The RPC server is unavailable."

Use one of the following to work around this problem:

Before you create your Word object, first create a temporary Word object. After you create your object, close the temporary object. This causes Word to act properly when you control it through Automation (that is, if a user interactively starts Word, a new instance of Word is opened for the user). The automation instance remains hidden and separate. See the Steps to Reproduce Behavior section for an example of this workaround.

Make the Word object visible immediately after using the CreateObject function. For example:

      Set wrdApp = CreateObject("Word.Application")
      wrdApp.Visible = True

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.


Steps to Reproduce Behavior
Make sure Microsoft Word is not running before following these steps. You might need to temporarily close any Mail programs that use Microsoft Word.

Start a new Visual Basic application.

Set a reference to the "Microsoft Word 8.0 Object Library." For Word 2000, set the reference to the "Microsoft Word 9.0 Object Library."

Create a new Module and copy the following code into the module:

      Option Explicit

      Dim wrdApp As Word.Application

      Private Sub CreateWordObject()
          'Test if object is already created before calling CreateObject:
          If TypeName(wrdApp) <> "Application" Then
              Set wrdApp = CreateObject("Word.Application")
          End If
      End Sub

      Private Sub UseWordObject()
          MsgBox TypeName(wrdApp) 'if displays "Application" then
              'Reference to Word is valid, else reference is invalid and
              'an error occurs on the following line:
          MsgBox wrdApp.Name
      End Sub

      Private Sub CloseWordObject()
          If TypeName(wrdApp) = "Application" Then
              Set wrdApp = Nothing
          End If
      End Sub
Run the CreateWordObject procedure. A hidden instance of Microsoft Word is created.

Run the UseWordObject procedure. The message boxes should display "Application" and "Microsoft Word."

Start Microsoft Word (using the Windows Start button, Windows Explorer or the Microsoft Office toolbar, and so forth.)

Quit Microsoft Word.

Run the UseWordObject procedure.

RESULT: The first message box displays "Object", which indicates the reference to Word is no longer valid. The next message box results in the Automation error when you attempt to use the Word object.

Replace the CreateWordObject procedure with the following new procedure and repeat the previous steps. You should no longer receive the Automation error. Be sure to run the CloseWordObject procedure to close the hidden instance of Word:
    Private Sub CreateWordObject()
        Dim temp As Word.Application
        'Test if object is already created before calling CreateObject:
        If TypeName(wrdApp) <> "Application" Then
            Set temp = CreateObject("Word.Application")
            Set wrdApp = CreateObject("Word.Application")
            Set temp = Nothing
        End If
    End Sub
NOTE: This workaround does not work when a document is launched directly through the Window Explorer, typically when someone double-clicks a document.

Additional query words: OLE automation

Keywords          : kbAutomation kbWord kbGrpDSO kbOffice2000 kbVBA500 kbword2000
Version           : WINDOWS:2000,5.0,97; :
Platform          : WINDOWS
Issue type        : kbbug

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
How nice of MS, Hmmm?
Its lucky they have a workaround
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.