Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Integer, ByVal dwReserved As Integer) As Integer
Public Shared Function IfOnline() As Boolean
Const FLAG_ICC_FORCE_CONNECTION As Integer = &H1
Return InternetCheckConnection("http://www.baidu.com", FLAG_ICC_FORCE_CONNECTION, 0)
End Function
if IfOnline() =True then
msgbox("网络通畅")
else
msgbox("网络不通畅")
end if
本文介绍了一个使用VBA编写的函数,该函数通过调用wininet.dll库中的InternetCheckConnection函数来检测本地计算机是否可以连接到指定的URL,从而判断网络是否畅通。函数返回True表示网络通畅,False表示网络不通畅。
1780

被折叠的 条评论
为什么被折叠?



