Error 462: The remote server machine does not exist when working with Word via Excel VBA

后端 未结 3 1256
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 02:08

I open a Word file programmatically in Excel VBA and add/edit contents using bookmarks.

I find that on alternate runs, I get

Error 462: The re

相关标签:
3条回答
  • 2020-12-04 02:15

    You have two unqualified references to Word objects:

    objSelection.Style = ActiveDocument.Styles("Heading 1")
    

    which appears twice, needs to be:

    objSelection.Style = objWord.ActiveDocument.Styles("Heading 1")
    

    Otherwise you're creating an implicit reference to Word that you can't destroy in your code.

    0 讨论(0)
  • 2020-12-04 02:16

    [SOLVED] Err 462 – "The remote server machine does not exist or is unavailable"

    ErrResume:
        On Error GoTo ErrPaste
            Set objDoc = objWord.Documents.Open(ExistingEvidenceDoc)
        On Error GoTo 0
    
    ErrPaste:
      'The remote server machine does not exist or is unavailable
        If Err.Number = 462 Then
            Set wdApp = CreateObject("Word.Application")
            Resume ErrResume
        End If
    
    0 讨论(0)
  • 2020-12-04 02:30

    You should first ensure there are no oprhan winword.exe in task manager. Kill then or log out/in to get rid of them.

    Then you should add something like this code to the end to 'explcitly' close word:

    (I'm not sure of the exact syntax, hopefully you can work it out)

    IF Not(objWord Is Nothing) Then
    
        objWord.Close(False)
        Set objWord = Nothing
    
    End If
    

    You should add something similar to your error handler.

    What often happens is during development and debugging, sometimes word doesn't get closed properly and 'orphan' processes hang around even though they are not visible.

    You may also wish to use

    Set objWord = New Word.Application
    

    instead of

    Set objWord = CreateObject("Word.Application")
    

    as that gives you autocomplete etc.

    But there area advantages to each way.

    0 讨论(0)
提交回复
热议问题