VBA检测网络是否已连接

分类:代码, 博客 标签:

VBA中调用API函数InternetGetConnectedState,用很简单的方法就能在你的VBA代码中实现判断本地机器网络是否已连接,具体源代码如下:

Option Explicit
'================================
' 检查网络是否已连接
'
' http://www.cnhup.com
'================================
Public Declare Function _
  InternetGetConnectedState _
  Lib "wininet.dll" (ByRef lpdwFlags As Long, _
  ByVal dwReserved As Long) As Long

Public Const _
  INTERNET_CONNECTION_MODEM_BUSY As Long = &H8
Public Const _
  INTERNET_RAS_INSTALLED As Long = &H10
Public Const _
  INTERNET_CONNECTION_OFFLINE As Long = &H20
Public Const _
  INTERNET_CONNECTION_CONFIGURED As Long = &H40


Public Function IsNetConnectOnline() As Boolean
    IsNetConnectOnline = InternetGetConnectedState(0&, 0&)
End Function


分类:代码, 博客 标签:

发表评论

You must be logged in to post a comment.