Excel/VBA - Abort script if network connection does not exist

前端 未结 3 976
無奈伤痛
無奈伤痛 2021-01-23 11:19

Are there any VBA code to look for a present internet connection?

I have a code that will run on a timer. This code will open a file on a local network share drive.

3条回答
  •  天涯浪人
    2021-01-23 11:57

    You can check the Len of Dir on the shared drive you're trying to get to:

    Option Explicit
    Sub TestForNetworkDrive()
    
    'suppose the file we want is at Z:\cool\vba\files\file.txt
    If Len(Dir("Z:\cool\vba\files\file.txt")) = 0 Then
        'handle network not available issue
        MsgBox ("Network share not found...")
    Else
        'do timer-based code here
        MsgBox ("Let's get to work!")
    End If
    
    End Sub
    

提交回复
热议问题