使用VBA检查网络连接 [英] Checking network connection using vba
本文介绍了使用VBA检查网络连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么方法可以检查vba中的NEtwork连接吗?
Is there any way to check NEtwork connection in vba?
我正在使用以下命令:
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
推荐答案
除了翻转if和else部分之外,您所做的几乎是正确的,
What you are doing is almost correct except flip the if and else parts,
即当Dir("O:\") = ""
= 您未连接
当它返回时,表示您已经建立连接.
and when it returns something means you have a connection.
Dir 函数是用于返回指定目录中的第一个文件名和属性列表.
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
这篇关于使用VBA检查网络连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文