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 'net card connection Private Const NETWORK_ALIVE_WAN = &H2 'RAS connection Private Const NETWORK_ALIVE_AOL = &H4 'AOL 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:

  1. Copy the code above
  2. Open any workbook/document
  3. Press Alt + F11 to open the Visual Basic Editor (VBE).
  4. Click Insert from the VBE Command Bar and select Module
  5. Double-click the new module
  6. Paste the code on the new module
  7. Close the VBE and save the file
  8. Press Alt + F8
  9. Run the macro IsConnection
 

Test the code:

  1. 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.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express