ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Remote Machine not available (https://www.excelbanter.com/excel-programming/433934-remote-machine-not-available.html)

Alan[_8_]

Remote Machine not available
 
Sometimes the code below encounters a runtime error (462) at the line
"Word.Application.Visible." That error says: "The remote server
machine does not exist or is not available.

What might cause this error? Alan

Function StartWord() As Boolean
StartWord = False
' Try to open an existing instance of Word
On Error Resume Next
Set Word = GetObject(, "Word.Application")
On Error GoTo 0
' If Word is not started, start a new instance
If Word Is Nothing Then
Set Word = GetObject("", "Word.Application")
End If

Word.Application.Visible = True

StartWord = True
End Function

papou[_4_]

Remote Machine not available
 
Hello Alan
If the GetObject method returns an error, then you must use the CreateObject
method.
Your code uses the GetObject twice.
You should amend to:
On Error Resume Next
Set Word = GetObject(, "Word.Application")
' If Word is not started, start a new instance
If Err < 0 Then
Set Word = CreateObject("Word.Application")
End If
On Error GoTo 0

Also, you should avoid using variables with names that could refer to an
existing object in Excel:
Set AppWord =
instead of
Set Word =

HTH
Cordially
Pascal

"Alan" a écrit dans le message de news:
...
Sometimes the code below encounters a runtime error (462) at the line
"Word.Application.Visible." That error says: "The remote server
machine does not exist or is not available.

What might cause this error? Alan

Function StartWord() As Boolean
StartWord = False
' Try to open an existing instance of Word
On Error Resume Next
Set Word = GetObject(, "Word.Application")
On Error GoTo 0
' If Word is not started, start a new instance
If Word Is Nothing Then
Set Word = GetObject("", "Word.Application")
End If

Word.Application.Visible = True

StartWord = True
End Function





All times are GMT +1. The time now is 02:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com