How to handle "462: The remote server machine does not exist"

pitaszek

Board Regular
Joined
Jul 20, 2012
Messages
85
Hi Guys,

I am struggling with how to always handle the 462 error successfully. I am operating on VDI and I try to open a file to read some details from there. My experience show that it will finally open the file after 2 or 3 attempts.

The code I've written for that goes like this and still sometimes fails letting the error to pop up. I'd appreciate if someone could do some corrections:

Code:
For k = 1 To 2
    Set sourceWB = Workbooks.Open(strFile & "Looping stuff.xlsm")
    On Error Resume Next
    
    If Err.Number <> 0 Then
        WasteTime (10)
        Set sourceWB = Workbooks.Open(strFile & "Looping stuff.xlsm")
    End If
    On Error GoTo 0
Next k

and here is some delay logic meant to wait for 10 seconds:

Code:
Sub WasteTime(Finish As Long) 
    Dim NowTick As Long
    Dim EndTick As Long
 
    EndTick = GetTickCount + (Finish * 1000)
     
    Do
 
        NowTick = GetTickCount
        DoEvents
 
    Loop Until NowTick >= EndTick
 
End Sub

Regards,
Witek
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Main thing would be move the On Error instruction before the first try.
Code:
ir=5
On Error Resume Next
For k = 1 To ir
   err.clear
    Set sourceWB = Workbooks.Open(strFile & "Looping stuff.xlsm")
    If Err.Number <> 0 Then
        WasteTime (10)
   Else
        Exit For
    End If
Next k
On Error GoTo 0
And you can use a parameter to optimize the number of retries.
Still you must come up with some code to deal with failure to open the file even after a 100 loops :)
 
Upvote 0
Hi

Perhaps a way to partially tackle this is to try 3 times, and then ask the user to try again.

Code:
Dim FailedOpen as Boolean
For k = 0 To 2
    FailedOpen = False

    On Error Resume Next
    Set sourceWB = Workbooks.Open(strFile & "Looping stuff.xlsm")
    
    If Err.Number = 462 Then 'make sure this is the correct error number
        FailedOpen = True
        WasteTime (10)
        Set sourceWB = Workbooks.Open(strFile & "Looping stuff.xlsm")
    ElseIf Err.Number <> 0 Then
        GoTo ErrHandler
    Else
        Exit For
    End If
    On Error GoTo 0
Next k

If FailedOpen = True then 
    box = MsgBox ("Failed to open file. Try again?", vbRetryCancel, "Error")
    If box = vbRetry Then GoTo retryopen
    If box <> vbRetry Then Exit Sub
End If

Exit Sub

ErrHandler:
MsgBox "Unexpected error occurred. Program execution has been stopped.", vbCritical, "Error"
End Sub

I made the error handling more specific so that the code only retries to open the file if you get the specific error you described. If you get another error, the code proceeds to a non-specific error handler.
 
Last edited:
Upvote 0
I feel like this gets into infinite loops in both cases. Do you have any idea why this can be like that?

Regards,
Witek
 
Upvote 0
Neither of the two answers will cause infinite loops. Bob's code loops five times and then gives up, mine loops three times after which it asks the user to try again (if yes, three more loops follow, and so on).

I noticed I forgot a label line in my code. Change:
Code:
Dim FailedOpen as Boolean

retryopen:
For k = 0 To 2
    FailedOpen = False
'....
 
Upvote 0
try to debug step by step.

Maybe there is some other line of code that gets you back to the beginning?
 
Upvote 0

Forum statistics

Threads
1,215,388
Messages
6,124,658
Members
449,177
Latest member
Sousanna Aristiadou

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top