View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
urkec urkec is offline
external usenet poster
 
Posts: 131
Default Attempting to use VBA to Ping within Excel...

"Andy Dawkins" wrote:

Thank you urkec for your responce. I noticed that you mentioned that
Win32_PingStatus was added for windows XP. If I'm using Windows 2000 what
would I need to do to make it work?



I found that code he

http://www.rlmueller.net/PingComputers.htm

You can find other two samples there, one uses WScript.Shell Exec method to
execute the Ping command and then checks it's output to determine if ping was
successful. The other uses WScript.Shell Run method. Both will work with
Windows 2000 (the first sample requires Windows Script Host 5.6, the other
WSH 5.1) If you use WshShell.Exec you won't be able to prevent Command Prompt
appearing on the screen, if you use WshShell.Run you will have to write the
Ping command output to a temporary txt file, so those are not ideal
solutions. The samples are VBScript, VBA the code would look something like
this:


Function Ping2(ByVal Host As String, _
ByVal Pings As Integer, ByVal TimeOut As Integer) As Boolean

Status = CreateObject("WScript.Shell"). _
Exec("%comspec% /c Ping -n " & CStr(Pings) & _
" -w " & CStr(TimeOut) & " " & Host).StdOut.ReadAll

'Debug.Print Status

If InStr(Status, "TTL=") = 0 Then
Ping2 = False
Else
Ping2 = True
End If

End Function


Then you can call Ping2 like this:


Ping2("ANAME", 1, 750)



--
urkec