Is there any way to check NEtwork connection in vba?
I am using this command:
If Dir("O:\") = "" Then
MsgBox "you have network connection"
Else
MsgBox "No Connection"
End If
but it doesnt work and I am getting a run time error
What you are doing is almost correct except flip the if and else parts,
i.e. when Dir("O:\") = ""
= You are not connected
and when it returns something means you have a connection.
The Dir function is used to return the first filename from a specified directory, and list of attributes.
Sub Test_Connection()
If (Len(Dir("O:\"))) Then
MsgBox "Connected"
Else
MsgBox "No Connection"
End If
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With