Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is connected macro

Status
Not open for further replies.

jflaurin

Technical User
Dec 1, 2007
12
0
0
I need write a macro that will check if the user is connected to the Intranet, I can't simply check if there's an internet connection. What I was thinking is to try to open an intranet page from a macro and if it returns an error then I know there's no connection...but how can I do that, ???
 




Hi,

What code do you have so far?

What application are you coding your VBA in?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
And please be as clear as possible.

On one hand you use Intranet, but you also mention "internet connection".

Are you really talking about an IntRAnet? If it is a company intRAnet, then - normally - if the computer has a LAN connection, then that machine is connected to the intRAnet. Whether the intranet servers are functioning is another matter.

Please answer Skip's questions, as this is a VBA forum, and therefore the application you are using can make a difference.

Although, I believe you are basically on the correct track. Attempt to load a page and use error trapping to determine if it is loading correctly, or not.

Gerry
 
I've lost the code now, but I used to have an app that I'd used for this type of problem. It was a bit flash, and used SAPI to notify me when a specific server went up/down but pinging them and checking the response codes.

I've lost the code years ago, but this snap from the KPD Team should help you. Slap it on a new module, change Private Sub Form_Load to Public Function CheckServer() and change " to the server you want to check...

Code:
Const NETWORK_ALIVE_AOL = &H4
Const NETWORK_ALIVE_LAN = &H1
Const NETWORK_ALIVE_WAN = &H2
Private Type QOCINFO
    dwSize As Long
    dwFlags As Long
    dwInSpeed As Long 'in bytes/second
    dwOutSpeed As Long 'in bytes/second
End Type
Private Declare Function IsDestinationReachable Lib "SENSAPI.DLL" Alias "IsDestinationReachableA" (ByVal lpszDestination As String, ByRef lpQOCInfo As QOCINFO) As Long
Private Sub Form_Load()
    'KPD-Team 2001
    'URL: [URL unfurl="true"]http://www.allapi.net/[/URL]
    'E-Mail: KPDTeam@Allapi.net
    Dim Ret As QOCINFO
    Ret.dwSize = Len(Ret)
    If IsDestinationReachable("[URL unfurl="true"]www.allapi.net",[/URL] Ret) = 0 Then
        MsgBox "The destination cannot be reached!"
    Else
        MsgBox "The destination can be reached!" + vbCrLf + _
           "The speed of data coming in from the destination is " + Format$(Ret.dwInSpeed / 1024, "#.0") + " Kb/s," + vbCrLf + _
           "and the speed of data sent to the destination is " + Format$(Ret.dwOutSpeed / 1024, "#.0") + " Kb/s."
    End If
End Sub

Or even better, make it a Parameter ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top