|
|
|
|
|
|
Multiple Apps
|
Check, if a RAS/Internet connection exists
|
|
Ease of Use
|
Intermediate
|
Version tested with
|
97, 2000, 2002, 2003
|
Submitted by:
|
Paleo
|
Description:
|
Many coders use macros to go to certain web pages, but wouldn't it be better to check if there is a connection available first?
|
Discussion:
|
The existence of a RAS/internet connection is checked by this code.
|
Code:
|
instructions for use
|
Private Const NETWORK_ALIVE_LAN = &H1
Private Const NETWORK_ALIVE_WAN = &H2
Private Const NETWORK_ALIVE_AOL = &H4
Private Declare Function IsNetworkAlive Lib "Sensapi" _
(lpdwFlags As Long) As Long
Private Function IsNetConnectionAlive() As Boolean
Dim lngAlive As Long
IsNetConnectionAlive = IsNetworkAlive(lngAlive) = 1
End Function
Private Function IsNetConnectionLAN() As Boolean
Dim lngLAN As Long
If IsNetworkAlive(lngLAN) = 1 Then
IsNetConnectionLAN = lngLAN = NETWORK_ALIVE_LAN
End If
End Function
Private Function IsNetConnectionRAS() As Boolean
Dim lngRAS As Long
If IsNetworkAlive(lngRAS) = 1 Then
IsNetConnectionRAS = lngRAS = NETWORK_ALIVE_WAN
End If
End Function
Private Function IsNetConnectionAOL() As Boolean
Dim lngAOL As Long
If IsNetworkAlive(tmp) = 1 Then
IsNetConnectionAOL = lngAOL = NETWORK_ALIVE_AOL
End If
End Function
Private Function GetNetConnectionType() As String
Dim lngAlive As Long
If IsNetworkAlive(lngAlive) = 1 Then
Select Case lngAlive
Case NETWORK_ALIVE_LAN:
GetNetConnectionType = _
"More than one active LAN connection."
Case NETWORK_ALIVE_WAN:
GetNetConnectionType = _
"More than one active RAS connection."
Case NETWORK_ALIVE_AOL:
GetNetConnectionType = _
"There is a connection over AOL."
Case Else:
End Select
Else
GetNetConnectionType = _
"I can get another connection."
End If
End Function
Sub IsConnection()
MsgBox GetNetConnectionType
End Sub
|
How to use:
|
- Copy the code above
- Open any workbook/document
- Press Alt + F11 to open the Visual Basic Editor (VBE).
- Click Insert from the VBE Command Bar and select Module
- Double-click the new module
- Paste the code on the new module
- Close the VBE and save the file
- Press Alt + F8
- Run the macro IsConnection
|
Test the code:
|
- Open a file with the above code and run the macro IsConnection
|
Sample File:
|
InternetConnection.zip 11.26KB
|
Approved by mdmackillop
|
This entry has been viewed 84 times.
|
|