| PRB: Automation Error Calling Unqualified Method or PropertyID: Q189618 
 | 
While running code that uses Automation to control Microsoft Word 97 or Word 2000, you may receive one of the following error messages:
-or-Run-time error '-2147023174' (800706ba)
Automation error
Run-time error '462': The remote server machine does not exist or is unavailable
Visual Basic has established a reference to Word due to a line of code that calls a Word object, method, or property without qualifying it with a Word object variable. Visual Basic does not release this reference until you end the program. This errant reference interferes with automation code when the code is run more than once.
Modify the code so that each call to a Word object, method, or property is qualified with the appropriate object variable.
This behavior is by design.
To automate Microsoft Word, you establish an object variable that
usually refers to the Word Application or Document object. Other object
variables can then be set to refer to a Selection, a Range, or other
objects in the Microsoft Word object model. When you write code to use a
Word object, method, or property, you should always precede the call with
the appropriate object variable. If you do not, Visual Basic uses a hidden
global variable reference which it sets to the currently running instance.
If Word is shutdown, or if the declared object variable is released, the
hidden global variable will now reference an invalid (i.e., destroyed)
object. When running the automation code again, calls to this hidden object
variable will fail with the aforementioned error.
The following steps illustrate how to reproduce this problem, and how to
correct it.
      Option Explicit
      Private Sub Command1_Click()
         Dim oWord As Word.Application
         Dim oDoc As Word.Document
         Dim oRange as Word.Range
         Set oWord = CreateObject("Word.Application")
         With oWord
             .Visible = True
             .Activate
             .WindowState = wdWindowStateNormal
         End With
         Set oDoc = oWord.Documents.Add
         MsgBox "Document open", vbMsgBoxSetForeground
         With oDoc
             .PageSetup.LeftMargin = InchesToPoints(1.25)
         End With
         ' This example inserts text at the end of section one.
         Set oRange = ActiveDocument.Sections(1).Range
         With oRange
             .MoveEnd Unit:=wdCharacter, Count:= -1
             .Collapse Direction:=wdCollapseEnd
             .InsertParagraphAfter
             .InsertAfter "End of section."
         End With
         With oDoc
             .Saved = True
         End With
         Set oRange = Nothing
         Set oDoc = Nothing
         oWord.Quit
         Set oWord = Nothing
      End Sub 
.PageSetup.LeftMargin = InchesToPoints(1.25) 
.PageSetup.LeftMargin = oWord.InchesToPoints(1.25) 
Set oRange = ActiveDocument.Sections(1).Range 
Set oRange = oWord.ActiveDocument.Sections(1).Range 
For additional information, please see the following articles in the
Microsoft Knowledge Base:
Q178510 PRB: Excel Automation Method of Object '_Global'Failed
Q167223 Microsoft Office 97 Automation Help File Available on MSL
Additional query words: activex OLE
Keywords          : kbole kbActiveX kbAutomation kbVBp kbVBp400 kbVBp500 kbVBp600 kbWord kbGrpDSO kbOffice2000 kbVBA500 kbword2000 
Version           : WINDOWS:2000,4.0,5.0,6.0,97; :
Platform          : WINDOWS 
Issue type        : kbprb Last Reviewed: June 4, 1999